Getting A ReturnValue From Cmd.Parameters In C#?
Mar 29, 2010
I have just finished converted a vb.net app to c# and one of the lines is to get @ReturnValue from the parameter.I ended up having to CAST a lot of things..Is there not a easier wayhere is what i have
int rc = ((System.Data.SqlTypes.SqlInt32)(((System.Data.SqlClient.SqlParameter)(cmd.Parameters["@ReturnValue"])).SqlValue)).Value;
In vb.net it was as simple as doing this
Dim rc As Integer = Convert.ToInt32(cmd.Parameters("@ReturnValue").Value)
Alot easier :-)But the problem with C# is the property Value isn't available unless I Cast to SqlParameter and i also need to cast to Sqltypes.SqlInt32 - i can't just do a standard Convert.ToInt32
View 2 Replies
Similar Messages:
Apr 26, 2010
Since both retruns the value. Then whats is the difference between ParameterDirection.ReturnValue and ExecuteScalar()
int i = Convert.ToInt32(cmd.ExecuteScalar())
objCmd.Parameters.Add("@ColumnnTest", SqlDbType.Decimal).Value = objPropertiesClassName.Columnnumeric;
objCmd.Parameters["@Columnnumeric"].Direction = ParameterDirection.ReturnValue;
objCmd.ExecuteNonQuery();
int i = (int)objCmd.Parameters["@Columnnumeric"].Value;
View 1 Replies
Jul 13, 2010
How and where can I get the returnvalue from my "DeleteGuestById" method to show the right error message to my user?
I have this:
Protected Sub gvGuestlist_OnRowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles gvGuestlist.RowCommand
If e.CommandName = "DeleteGuest" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim data As DataKey = gvGuestlist.DataKeys(index)
Dim GuestId As Integer = data.Values("id")
odsGuestlist.DeleteParameters.Clear()
odsGuestlist.DeleteParameters.Add("id", GuestId)
odsGuestlist.Delete()
End If
End Sub
In my BLL:
<System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, False)> Public Function DeleteGuestById(ByVal ID As Integer) As Integer
Dim returnval As Integer
GuestlistAdapter.DeleteGuestById(ID, returnval)
Return returnval
End Function
I think I have to be in the ObjectDatasources' "OnDeleted" method but I have no what code to place there.
View 2 Replies
Nov 28, 2010
Im setting up an OData provider in visual studio. The error that im receiving really doesnt have anything to do with OData side of things.I have a table type in my ado entity data model and whenever I try to insert a record into this table i get the following error: {"The member with identity 'ReturnValue' does not exist in the metadata collection.Parameter name: identity"}
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
[code]...
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
Jun 7, 2010
I want to define a route that have 2 optional parameters in the middle of the URL the start an end parameters are digits
[Code].....
View 1 Replies
Dec 10, 2010
Since ASP.NET MVC3 RC2 I encounter a bug when posting values to a controller method of which one of the parameter is a nullable int. Steps to reproduce:
I've created a test method
[code]....
In MVC3 RC1 this was working without any problems with the nullable int
Update:
I don't seem to have the problem with a newly created MVC3 website. What could I have in my project that influence model binding to nullable int's? And why would there be a difference between RC1 and RC2?
View 10 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 21, 2010
here is my code for selectiong some records from db table
string strSql = "select * from mtblNBD where SentTo=@SentTo and InternalStatus Is NULL order by DeadLine desc";
SqlCommand com = new SqlCommand(strSql, con);
com.Parameters.Add("@SentTo", SqlDbType.NVarChar, 50).Value = (string)Session["uname"];
here I am using parameters for SenTo field but not for NULL so it is ok... or should I use parameters for this field where value is NULL , if yes then how can I use parameter for this
View 8 Replies
Jan 3, 2011
I have two examples to show you what I want to achieve here. But to point what's different about my question, Is that I'm having a parametrized URLs and I want to implement URL rewriting to my application. But I don't want to convert the parameter in the URL to be placed between slashes..."page.aspx?number=one" to "pages/one/" << NOT!
First example:
http://localhost:1820/Pages/Default.aspx?page=2&start=5
To
http://localhost:1820/Pages/page2
Second example:
http://localhost:1820/Items/Details.aspx?item=3
To
http://localhost:1820/Items/ItemName
But I'll still need all the parameters in the original URLs
View 2 Replies
Mar 30, 2011
I have a stored procedure that works fine for classic asp, but how can I get my output parameters data back from in /MVC 2 / linq/ entities framework model . I have inported the function also, but when i try to code it i dont get results ...i know this is a matter of lack of / knowledge or exmple because i have been scouring the web for it and cannnot find into that accually works.
here is the stored proc.
[Code]....
Here was the one of the few tries I did:
[Code]....
but it executes fine does not give me an error, but also does not return the info i need to the viewmodel
I keep seeing stuff about "ref" on the net but "ref" shows " arbument # should not be passed with the ref keyword.
So i am not sure if there is a problem with the model, or with my understanding this, Now for your info I can do the same step with returning a dataset from a stored procedure fine, but I dont want a data set I just want excatly the data in the output parameters from the stored procedure.
View 2 Replies
Oct 14, 2010
I am an ASP beginner, I have a stored precodure which accepts two input parameters. In my ASP project, I have a button click event
protected void OnAddClick(object sender, EventArgs e)
{
string concept = txtConcept.Text;
string keyword = txtKeyword.Text;
.......
int result = Helper.ConceptInsert(concept,keyword);
}
In my Helper.cs, I have a method as
public static int ConceptInsert(string description, string keyword)
{
int result = -1;
string connString = ConfigurationManager.ConnectionStrings["MySpaceConnectionString"].ConnectionString;
string commString = "exec dbo.Concept_Insert @description";
using (SqlConnection conn = new SqlConnection(connString))
{
using (SqlCommand comm = new SqlCommand(commString, conn))
{
comm.Parameters.Add(new SqlParameter("@description", description));
comm.Parameters.Add(new SqlParameter("@keyword", keyword));
conn.Open();
result = comm.ExecuteNonQuery();
}
}
return result;
}
But when I run the code, error message is always Procedure or function 'Concept_Insert' expects parameter '@keyword', which was not supplied. How can I pass those two parameters together to the stored procedure?
View 4 Replies
Jul 12, 2010
I consider the following an error, and not a feature:
When posting a request, any parameters are held in the HttpContext.Request.Form as key/value pairs. This is perfectly fine for the recipient of the request. Unfortunately, however, further down the chain these values still exist and take precedent in binding over new parameters created during processing.
This is obvious in the RenderAction scenario. If a new parameter is created in a view and passed through RenderAction, if the parameter has the same name as one of the initial request parameters (or a form field for that matter), then MVC Binding will bind the initial request form value to the Action being called, and not the new parameter being defined in the RenderAction call. What's even more frustrating, is there is no easy way to override the initial form values.
It really does not make sense that a value defined in one context, should live throughout the entire processing context... at least without the developer being able to determine it should remain. At a minimum, any new parameter defined in the process with the same name should either a) be received as a parameter and not a form value; or b) override the form value.
View 5 Replies
Jul 9, 2010
In this answer to my question of how to insert data into SQL Server he mentioned passing parameters instead of string concatenation like I currently have.
Is this really necessary for security? If so, what exactly is passing parameters? When i google it I get a lot about stored procedures. Is that what I want, I do not know about stored procedures....yet.
EDIT:
Ok, here is what I got. It seems to update the database correctly and eventually I will change the hard coded ints to inputs from a label. confirm if how I did this is not vulnerable to any sql injection or hacks.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
public partial class Stats : System.Web.UI.Page
{
public SqlDataReader DataReader;
public SqlCommand Command;
string queryString = ("INSERT INTO UserData (UserProfileID, ConfidenceLevel, LoveLevel, HappinessLevel) VALUES (@UID, @CL, @LL, @HL);");
//string queryString = ("INSERT INTO UserData (UserProfileID, ConfidenceLevel, LoveLevel, HappinessLevel) VALUES ('a051fc1b-4f51-485b-a07d-0f378528974e', 2, 2, 2);");
protected void Page_Load(object sender, EventArgs e)
{
LabelUserID.Text = Membership.GetUser().ProviderUserKey.ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
//connect to database
MySqlConnection database = new MySqlConnection();
database.CreateConn();
//create command object
Command = new SqlCommand(queryString, database.Connection);
//add parameters. used to prevent sql injection
Command.Parameters.Add("@UID", SqlDbType.UniqueIdentifier);
Command.Parameters["@UID"].Value = Membership.GetUser().ProviderUserKey;
Command.Parameters.Add("@CL", SqlDbType.Int);
Command.Parameters["@CL"].Value = 9;
Command.Parameters.Add("@LL", SqlDbType.Int);
Command.Parameters["@LL"].Value = 9;
Command.Parameters.Add("@HL", SqlDbType.Int);
Command.Parameters["@HL"].Value = 9;
Command.ExecuteNonQuery();
}
}
View 7 Replies
Jun 13, 2010
I need to be able to provide a page for the end user where thay can search in the following :
Search work
Category
Price
AdType
Location
and so on.
Its important that the user can copy the url and then use it later(and get the same settings). Its also important to be able to save these settings on the user in the database.
So far I have created a ModelView class that contains the parameters but I am not sure that this is the right way to go? Maby I should pass all inte the URL.
View 2 Replies
Jan 13, 2010
The urls on my site can become very long, and its my understanding that urls are transmisted with the http requests. So the idea came to compress the string in the url.From my searching on the internet, i found suggestions on using short urls and then link that one to the long url. Id prefere to not use this soltuion because1) I would have to do a extra database check to convert between long and short url.
That leaves in my head 2 options1) Hashing, i dont think this is a option. If you want a safe hashing algorithim, its going to be long.2) Compressing the url string, basicly having the server depress the string when when it gets the url parameters.3) Changing the url so its not descriptive, this is bad because it would make development harder for me ( This is a 1 man project ).Considering the vast amount posible amount of OS / browsers out there, i figured id as if anyone else has tried this or have some clever suggestions.If it mathers the url parameters can reach 100+ chars.Example: mysite.com/Reports/Ability.aspx?PlayerID=7737&GuildID=132&AbilityID=1140&EventID=1609&EncounterID=-1&ServerID=17&IsPlayer=True
EDIT:Let me clarify atm this is NOT breaking the site. Its more about me learning to find a good solution ( Im well aware this is micro optimisation, my site is very fast atm ) and making my site even faster ( To challage myself, and become a better coder ).There is also a cosmetic issue, i personaly think that a URL longer then the address bar looks bad.
View 8 Replies
Dec 20, 2010
I have one page that I am dynamicaly creating a URL complete with two parameters that I need on the destination URL page in my stored procedure that I will be running a sql report with.
here is my url that is created
[URL]
my two parms are ReqID and CoOpCode.
I need to capture those two parms for my stored procedures I found some examples of doing it however the example only shoewed for the int and not the string.
I have heard some folks say use java and other say just do it in the code behind either way is fine by me I guess but I do like the code behind.
How can I do this?
Then the next question is how to I pass those parms to my Sql Report that using the stored procedure.
View 13 Replies
Feb 17, 2010
i am trying to update a excel file using the oledb connections. But i am getting the following error:
"No value given for one or more required parameters."
This is my code:
String sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(@"TempUploads" + hdnExcelName.Value) + ";Extended Properties='Excel 8.0;HDR=NO'";
OleDbConnection objConn = new OleDbConnection(sConnectionString);
objConn.Open();
string sql = "update [Sheet1$] set [A8]='apple1.jpg'";
OleDbCommand objCmdSelect = new OleDbCommand(sql, objConn);
objCmdSelect.ExecuteNonQuery();
objConn.Close();
View 1 Replies
Jun 7, 2010
I know how to get back a single url parameter which is done using
string id = Request.QueryString["type"]
However, I am having problems passing and getting back two parameters. I am first passing the two parameters/argument using the following syntax
string name_one = "main"
string name_two = "category"
string needed_msg = "Zone.aspx?type=" + name_one + "&" + name_two;
Response.Redirect(needed_msg);
and I would like to get back the paramaters/arguments as two separate strings. How do I do it.
View 3 Replies
Feb 25, 2011
I have an asp.net 2.0 application which when it starts up need to read a number of parameters in order to enable the accessible functionalities for the user. It also needs to read database connection parameters among etc. I am currently using a singleton class to read all the parameters from an xml file. Is this the best way of doing this or should I add all the parameters in web.config? The app takes > 1minute to start How can I improve on the performance?
View 5 Replies
Nov 2, 2010
[Code]....
No value given for one or more parameters error?
View 10 Replies
Aug 5, 2010
I'm just about hitting the logging page of our company new website, every user has his own settings of restrictions, since i don't want to load those values from the database in each page, my current idea is to save it once he log in in a session as a class of "Employee" and use them at will.is this consider good approach or should i go another way?
View 12 Replies
Jun 22, 2010
Actually used to use Sql server, for that I add parameters like this
com.Parameters.Add("Field1",SqlDbType.Nvarchar,50).value=TextBox1.Text.
that works fine. but while using MSaccess and the datatype for of some table is Memo than how could I use parameter for that i am using System.Data.Odbc. cos here it is easy to do SqlDbType.Nvarcha cos there is shows Nvarchar but not Memo
View 3 Replies
Aug 3, 2010
I have a page containing a link to to MS Excel spreadsheet (I am able to assume that Excel is available as this is an intranet page). All works fine until I want to pass a parameter into the spreadsheet.
Normally I would do this with /e but this will not work I am starting Excel through a link.
Any ideas how I would pass the parameters into Excel?
(also - there may be multiple requests for the spreadsheet at any time with differing parameters!!)
View 1 Replies
Apr 21, 2010
when i worked in .NET 1.1 i used to pass parameters to user control using the method- (if the name of the usercontrol is "tables")
dim r As tables =
CType(Page.LoadControl("~/usercontrol/tables.ascx"), tables)
and calling public property of the usercontrols.
the problem is that i can't the way to do it in 2008 ver of .NET, it is not recognize the usercontrol.... how can i pass parameters to the usercontrol in run time?
View 10 Replies