C# - Dynamic Return Type Based On The Input - Create A Function Which Would Have Two Parameters
Feb 14, 2011
I want to create a function which would have two parameters
public **XYZ** GetOputput(string strToConvert, **ABC**)
What I want from this function, that I will send a string to this function and the datatype in which I want to convert this string [Ex: Int32,Int64, datetime etc..] and the return will be the same as the datatype I have sent as the input parameter.
I want to have something like this in my function:
[code]....
View 5 Replies
Similar Messages:
Mar 28, 2011
internal static void GetUserData(int userId, out string userName,
out string userEmail, out string userPassword)
{
using (SqlConnection con = Util.GetConnection())
{
con.Open();
using (SqlCommand cmd = new SqlCommand("usp_UD_SelectById", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@UD_ID", SqlDbType.Int).Value = userId;
cmd.Parameters.Add("@UD_UserName", SqlDbType.NVarChar, 100).Direction = ParameterDirection.Output;
cmd.Parameters.Add("@UD_Password", SqlDbType.NVarChar, 100).Direction = ParameterDirection.Output;
cmd.Parameters.Add("@UD_Email", SqlDbType.NVarChar, 100).Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
userName = Convert.ToString(cmd.Parameters["@UD_UserName"].Value);
userEmail = Convert.ToString(cmd.Parameters["@UD_Email"].Value);
userPassword = Convert.ToString(cmd.Parameters["@UD_Password"].Value);
}
}
}
and the call
string userEmail;
string userName;
string userPassword;
MemberHelper.GetUserData(userId, out userName, out userEmail, out userPassword);
Sometimes I need to get just one parameter from the out parameters, how can I call the function when I want to get just one:
string userPassword;
MemberHelper.GetUserData(userId,"","",out userPassword);
View 1 Replies
Jul 22, 2010
I pass two parameters to my repository to return one record
I am strugling to wite the code to return one record.
Here is my repository-
public Classifieds_Ads GetUserClassifiedDetailsToModify(int classifiedid, Guid UserGuid)
{
return context.Classifieds_Ads.Where(c => c.User.Id == UserGuid && c => c.CatID == classifiedid);
}
View 1 Replies
Jun 16, 2010
I have a method like:
public T Get<T>(string key)
{
}
Now say I want to return "hello" if the type is a string, and 110011 if it is type int.
how can I do that?
typeof(T) doesn't seem to work.
I ideally want to do a switch statement, and return something based on the Type of the generic (string/int/long/etc).
View 5 Replies
Jan 28, 2011
I have create a table and create edmx file, and I create a Stored Procedure that return a single row (select by primary key), and I want the edmx to have a function that calls that SP and return a type.
View 1 Replies
Jan 25, 2010
I have the following statement, I want to turn it into a Public Shared Function :
If isEmployee Then
Dim employeeInstance As New Employee
employeeInstance = GetEmployeeInstanceByUserId(userId)
Return employeeInstance
Else
Dim studentInstance As New Student
studentInstance = GetStudentInstanceByUserId(userId)
Return studentInstance
End If
Public Shared Function GetWorkerInstance(Byval isEmployee as Boolean) As ...(not sure what to write here)...
There two possible return Type. I'm not sure what I should declare for the function return type.
View 2 Replies
Jan 12, 2011
I have two text boxes for the user to enter UserName & First Name, both these fields are optional and not mandatory to fill.
once the user presses the Search button, i execute the following query to fetch matching records.
[Code]....
The problem is, in cases where User leaves both the textbox or one of the textbox empty/blank, in that case that particular field should be removed from where clause.
More like if something is entered then search for that particular record otherwise search for all the records.
View 2 Replies
Oct 13, 2010
I am familiar with creating and persisting dynamic controls on the first load of a page and on subsequent postbacks but I am having trouble with the following user initiated scenario...
In my demo I have a placeholder, two buttons and a literal
[code]....
View 1 Replies
Jun 22, 2010
I am trying to write a function that can be called to run a stored procedure. I pass the stored procedure name, followed by as many parameters as I need to run the procedure. I am able to do this by using the params keyword, so my function looks something like this;
[Code]....
How can I determine what the data type of the parameter is? Maybe I need to alter the string[] part, above?
View 5 Replies
Mar 10, 2011
How do i create a function that takes username as input and return it some thing like:
First time input :
John SHOULD RETURN John1
Second time input
John1 SHOULD RETURN John2
Third time input
John2 SHOULD RETURN John3
View 3 Replies
Nov 26, 2010
I have static html paypal buynow button that works great, but it's static.
[Code]....
But it is possible to change the values for the hidden inputs from .net codebehind code? I found this post which takes a different approach of sending these hidden fields instead as a query string to paypal. Not sure I like that though as would this not possiby explose some of those fields like the return page?
http://www.makaistudio.com/mksBlog/post/ASPNet-and-Paypal-buy-now-button-Offer-discount-at-checkout-in-code-behind.aspx
Basically what id like to do change the important parts of the button and info I'm sending to make it dynamic.I know I can do something like this in the markup, but that would mean having to fetch data mulitple times was hoping I could somehow adderss the field values directly in the codebehind. Or possibly dynaically generate and insert the entire changing input type fields from the codebehind
<input type="hidden" name="invoice" value="<%= getinvoice()%>">
Possible to add them with something like this: myform.Attirbutes.Add (???). If so how do I contruct these input types in .net?As far as return logic security, I've tested that it's solid, i just need to automate the button process so I don't have to create a buy now page and button for each product.
View 1 Replies
May 28, 2010
I'm new to web dev and c# so please bare with me. I am trying to create a dynamic gridview in a web form for users to to answer questions with (code below).
The dificulty im having is that i am nesting a dropdwonlist in the gridview and want to be able to dynamically set the list values based on parameters (of the row they are on). These values are in the main dataset for the gridview as each row represents a questionid and question text and then a ddl for the criteria...
I just don't know how to set the values for the dropdown all the code so far is below... just need to be able to populate the dropdowns with the relevant values.
I have created a stored proc to return the different criteria based on the questionid and questionGroupid which is the dataset that populates the other fields in the gridview: dbo.usp_QuestionCriteria @QuestionGroupId, @QuestionId
I have added this as a tableadapter called criteriaTableAdapter in a xsd file as well using the wizard... not sure if this is the right option though or just use the same method as i have for the other stored procedure as in the code below:
[CODE
]using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Sql"].ConnectionString);
con.Open();
SqlCommand com = new SqlCommand("usp_QuestionGroupDS", con);
com.CommandType = CommandType.StoredProcedure;
SqlDataAdapter ada = new SqlDataAdapter(com);
DataSet ds = new DataSet();
ada.Fill(ds);
for (int i = 0; i < ds.Tables.Count; i++)
{
if (ds.Tables[i].Rows.Count > 0)
{
GridView gvDynamicQuestion = new GridView();
gvDynamicQuestion.Width = Unit.Pixel(700);
gvDynamicQuestion.BorderWidth = Unit.Pixel(0);
gvDynamicQuestion.Caption = "<div id="nifty" class="QuestionGroup"> <b class="rtop"><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4"></b></b>" + ds.Tables[i].Rows[0]["Category"].ToString() + " Questions<b class="rbottom"><b
class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b></div>";
gvDynamicQuestion.AutoGenerateColumns = false;
gvDynamicQuestion.ShowFooter = true;
TemplateField tf = null;
tf = new TemplateField();
tf.HeaderTemplate = new DynamicGridViewTextTemplate("QuestionId", DataControlRowType.Header);
tf.ItemTemplate = new DynamicGridViewTextTemplate("QuestionId", DataControlRowType.DataRow);
tf.FooterTemplate = new DynamicGridViewTextTemplate(DataControlRowType.Footer, ds.Tables[i].Rows.Count);
gvDynamicQuestion.Columns.Add(tf);
tf = new TemplateField();
tf.HeaderTemplate = new DynamicGridViewTextTemplate("Question", DataControlRowType.Header);
tf.ItemTemplate = new DynamicGridViewTextTemplate("Question", DataControlRowType.DataRow);
gvDynamicQuestion.Columns.Add(tf);
tf = new TemplateField();
tf.HeaderText = "Criteria";
tf.HeaderTemplate = new DynamicGridViewTextTemplate("Criteria", DataControlRowType.Header);
tf.ItemTemplate = new DynamicGridViewDDLTemplate();
gvDynamicQuestion.Columns.Add(tf);
////tf = new TemplateField();
////tf.HeaderText = "Criteria";
////tf.ItemTemplate = new DynamicGridViewDDLTemplate();
////gvDynamicQuestion.Columns.Add(tf);
gvDynamicQuestion.DataSource = ds.Tables[i];
gvDynamicQuestion.DataBind();
phDynamicGridHolder.Controls.Add(gvDynamicQuestion);
}
}
}
protected void DynamicGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
//
}
}
}
public class DynamicGridViewTextTemplate : ITemplate
{
string _ColName;
DataControlRowType _rowType;
int _Count;
public DynamicGridViewTextTemplate(string ColName, DataControlRowType RowType)
{
_ColName = ColName;
_rowType = RowType;
}
public DynamicGridViewTextTemplate(DataControlRowType RowType, int QuestionCount)
{
_rowType = RowType;
_Count = QuestionCount;
}
public void InstantiateIn(System.Web.UI.Control container)
{
switch (_rowType)
{
case DataControlRowType.Header:
Literal lc = new Literal();
lc.Text = "<b>" + _ColName + "</b>";
container.Controls.Add(lc);
break;
case DataControlRowType.DataRow:
Label lbl = new Label();
lbl.DataBinding += new EventHandler(this.lbl_DataBind);
container.Controls.Add(lbl);
break;
case DataControlRowType.Footer:
Literal flc = new Literal();
flc.Text = "<b>Total No of Questions:" + _Count + "</b>";
container.Controls.Add(flc);
break;
default:
break;
}
}
private void lbl_DataBind(Object sender, EventArgs e)
{
Label lbl = (Label)sender;
GridViewRow row = (GridViewRow)lbl.NamingContainer;
lbl.Text =DataBinder.Eval(row.DataItem, _ColName).ToString();
}
}
public class DynamicGridViewDDLTemplate : ITemplate
{
// Implementation of ITemplate
public void InstantiateIn(System.Web.UI.Control container)
{
// Create a DDL
DropDownList ddl = new DropDownList();
//Attach method to delegate
ddl.DataBinding += new System.EventHandler(this.ddl_DataBind);
container.Controls.Add(ddl);
}
//Method that responds to the DataBinding event
private void ddl_DataBind(object sender, System.EventArgs e)
{
//DropDownList ddl = (DropDownList)sender;
//DataGridItem container = (DataGridItem)ddl.NamingContainer;
//ddl.Data.Checked = [Data binding expression];
}
}
[/CODE]
View 7 Replies
Apr 20, 2010
could u tell me add controls to a page base on user inputs,
i know the basic of creating a button dynamically but here I have to to add few controls based on user input and how to identify event for each dynamically create control.
View 2 Replies
May 15, 2010
I have form in ASP.Net 4 (C# backend) that a user fills out to enter a new game quote into my DB. I have created the form and this lets the user add only a single quote at a time, what I would like to do is give the user a drop down box to let him/her choose to add up to 5 quotes at a time. The problem comes in how to generate the extra input forms based on what the user chooses. I have been going over my ASP.Net 4 book but it really does not cover this.
View 2 Replies
Aug 14, 2012
How can I create FB and gmail type web base chat in Asp.net ....
View 1 Replies
Feb 16, 2011
[Code]....
When I want to get the output values its okay but I also want returning a table as a result data.But Datareader has no rows.is it possible if I want a returning query result and multiple output values togather ?I wrote a test above.I can get output values as sqlparameters. But Datareader attached to a Gridview is empty.can you detect whats wrong here and it doesnt return a query result.So stored procedure is not standart or ı am doing something wrong.this doesnt raise any exception.but not returning any data.
[code]....
View 8 Replies
Dec 23, 2010
I want to create a common unit test function to check all functions based on parameter
for e.g
[code]....
what logic should i write inside this method so that by passing a actual function in parameter methodname and then the common method should execute that function and should return the output.
i am using entity framework for all functions which has been created in my project and now i dont want to create a separate unit test function for each function.just one function should do the job based on different parameters...
is that possible.. ?
View 4 Replies
Aug 24, 2010
I've tried to override error message when input incorrect data type in input field on HTML form.For example I have the model like this.
public class Person
{
public string FirstName {get;set;}
public int Age {get;set;}
}
For view, I put text input for Age to get it value.When type some string in Age text box like 'test' and press submit button.
I got this error message ,The value 'xxx' is not valid for AgeHowever, I want to change this message and try many way. There 's nothing effect this message value.
View 1 Replies
May 27, 2010
how can i generate rtf file based on input field(textbox input by user) c#
View 3 Replies
May 12, 2010
I am using jquery ajax method on my aspx page,which will invoke the webmethod in the code behind.Currently the webmethod takes a couple of parameters like firstname,lastname,address etc which I am passing from jquery ajax method using
data:JSON.stringify({fname:firstname,lname:lastname,city:city})
now my requirement has been changed such that,the number and type of parameters that are going to be passed is not fixed for ex.parameter combination can be something like fname,city or fname,city or city,lname or fname,lname,city or something else.So the webmethod should be such that it should accept any number parameters.I thought of using arrays to do so, as described here.
But I do not understand how can I identify which and how many parameters have been passedto the webmethod to insert/update the data to the DB.
View 4 Replies
Jan 22, 2010
Can my WebMethod return an XmlDocument as return type?
When I try to consume the web service I'm still not getting XML. It appears as though a reference to the method is being returned rather than say a string containing XML.
<WebMethod()> _
Public Function CustomerSearch(ByVal lastName As String, ByVal firstName As String, ByVal companyName As String, ByVal city As String, ByVal state As String, ByVal email As String) As XmlDocument
' Create XML doc
Dim doc As XmlDocument = New XmlDocument()
' some more code
Return doc
End Function
View 4 Replies
Jun 8, 2010
Given the function
[code]....
When 'return false' is fired, I'm assuming that the function is stopped at that point and there's no need for exit fors and things like that?
View 1 Replies
Mar 24, 2010
I need to send emails based on users input time and day (based on their time zone)? Kind of a reminder.
For Example: User input 2:00pm Eastern Time on my server I have different time zone, how to calculate the time and send the email at users time-zone. Its a web application. What is the best way to accomplish it using asp.net c#? If somebody already done it in the past I will be glad to take a look at source code.
View 1 Replies
Oct 21, 2010
I am always thinking about validation in any kind on the webpage (PHP or ASP, it doesn't matter), but never find a good and accurate answer. For example, a I have some GET-Parameter, which defines a SQL query like DESC oder ASC. (SQL-Injection?) Or I have a comment-function for user, where the data is also saved in a database.
Is it enought to check for HTML-tags inside the data? Should the validation done before adding it to the database or showing it on the page? I am searching for the ToDo's which should be always performed with any data given from "outside".
View 3 Replies
Jan 17, 2010
I try to have an URL like this /Forum/Index/2 for url I have a route {controller}/{action}/{page} in my global.asax
If i test the above url with the Route Debugger it corresponds to the above route ( and some other but this is the fist one in the list ) but if I create an url with the ActionLink
( like this : [Code]....
),
this methode return me this URL /Forum/Index?page=2 Is there a way to a have an url with nothing in querystring with the ActionLink methode ? Gauthier
View 10 Replies