DataSource Controls :: ParameterDirection.ReturnValue Vs ExecuteScalar()?
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
Similar Messages:
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
Jul 27, 2010
I have a simple procedure which updates a table. The procedure works fine and I have tested it in Management Studio. However when I am calling that procedure from code, nothing is happening. cmd.ExecuteScalar returns null when it should return the ID.Has anyone faced anything similar? Any pointers as to how this can be resolved?
View 3 Replies
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
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
Dec 6, 2010
I have this SQL Select statement to select the basket id where the user id equals a specific ID.I want to store the result of the query in a variable, so I thought I could have done:
BasketPage.SelectCommand="SELECT BasketID FROM tblBasket WHERE (UserID = '9f96bd94-91b9-4328-8214-4eac179c3a26')"
var BasketID = BasketPage.ExecuteScalar().ToString();
But apparently I need to create a new instance of an SQL Command for it to work, how can I do this for the BasketPage Select Command?
View 2 Replies
Jan 8, 2010
I have the SqlCommand Problem. cmd is the sqlcommand and when run cmd.Executescalar(), what will it return??
As I have the problem below code that it always prompt invalid cast which may be in the assigning BAtchno.
What do you think?? How to Correct below code??
--------------------------------------------------------
sSQL = "select max(batchno) from QI_WMS.dbo.WMS_StockRelease_Shipment with(nolock) "
+ " where convert(varchar, SRDate, 111) = @DateReceive and
WarehouseID=@WarehouseID";
[code]...
View 4 Replies
Aug 30, 2010
I need to carry the newly created value to another page using the ExecuteScalar method, I'm using the try catch finally but I'm a bit stuck with it,
[Code]....
View 6 Replies
Oct 21, 2010
I know for a fact that the SQL statement below returns NULL but my code statement "if (obj != null)" is not working.When I debug it I see a value of {} ... not sure what that is. Here is my code:
[Code]....
So, even if SQL returns NULL, it still validates obj as NOT NULL !
View 3 Replies
Dec 5, 2010
I posted a question about how to save the result of an SQL command to a variable and was told that the execute scalar method should be used, however I can't use it, I'm using the System.Data.SQLClient reference but still not finding it
View 3 Replies
Jan 4, 2010
I am using following oracle query and using executescalar() to fetch data
sql = "select username from usermst where userid=2"
string getusername = command.executescalar();
But It is showing me error "System.NullReferenceException: Object reference not set to an instance of an object"
This error comes when there is no row exist in database for userid=2
View 4 Replies
Oct 6, 2012
I use below code for my button event
int Result = _cmd.ExecuteNonQuery();
if (Result > 0)
{
Session["Login"] = true;
Response.Redirect("~/Managers.aspx?BehCode=" + Server.UrlEncode(TextBox1.Text));
}
But it didn't work it didn't go to managers.aspx page but when I replace code with below code it worked correctly it go to managers.aspx
int count = Convert.ToInt32(_cmd.ExecuteScalar());
if (count > 0)
{
Session["Login"] = true;
Response.Redirect("Managers.aspx?BehCode=" + Server.UrlEncode(Txtbeh.Text));
}
Why this happen whats exact different between two code?
View 1 Replies
May 7, 2015
ExecuteScalar requires an open and available Connection. The connection's current state is closed.
namespace ITS_Group{ public partial class Login : System.Web.UI.Page {
private DataTable GetData(SqlCommand cmd) {
DataTable dt = new DataTable();
String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings[1].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
[CODE]..
View 1 Replies
Oct 22, 2010
I hope this is the right forum for this question.The statement , object obj = cmd.ExecuteScalar() is returning 2010-10-22 18:25:36However is not bringing the last 3 digits (miliseconds).This is actually calling the following SQL query: select max(timeStamp) from Table1 which returns 2010-10-22 18:25:36.713 on query analyzer. As you can see "713" is not being included ...How do I bring this value?
View 2 Replies
Sep 30, 2010
I have VS 2010 professional. I am trying to open "ASP.Net Configuration" through Project -> ASP.Net Configuration.
It pops up the Notification about the ASP.Net Development Server localhost but doesn't open ASP.Net Configuration in the default browser.I clicked on the Root Url (by double clicking on the 'development server' at the right bottom from Notification Manager).
It throws following error
"An error was encountered. Please return to the previous page and try again."
Clicking on "How do i use this tool".It opened page with error.
Tool Has Timed Out
View 2 Replies
Sep 13, 2010
I'm using Visual Studio 2008, and my database is SQL Server 2000.
I want to add a connection to the Server Explorer in VS. The Data source is Microsoft SQL Server (SqlClient). After entering in all my information and I click Test Connection, it is successful.
But when I click OK, I get the error:
Unable to add data connection. ExecuteScalar requires an open and available connection. The connection's current state is closed.
View 3 Replies
Mar 10, 2011
i have problem white Object datasource. i have a multi-tier Application that include common layer ,DAL Layer,business logic and persantation layerwhen i add a object datasource to my page, it bring me only common layer classes . but i want use bisuiness layer classes what do i do ?
View 1 Replies
May 20, 2010
I have several web forms which use a GridView linked to a DataSource control which is defined at design time as follows:
<cc1:pgsqldatasource
id="dsStates"
runat="server"
connectionstring="<%$ ConnectionStrings:PgSqlConnection %>"
oldvaluesparameterformatstring="Original_{0}"
providername="<%$ ConnectionStrings:PgSqlConnection.ProviderName %>" >
</cc1:pgsqldatasource>
As you can see, the connectionstring parameter is defined to a specific connection string name and I need to be able to set such a parameter to a different value, for example, to a session variable content.
View 1 Replies
Nov 15, 2010
i am trying to create connection using OLEDB connection in my app. but i am not able to create the connection as in datasource i want to use Server.mappath, but cudn't find the right method to use it. i am trying to make connection with Access database file. following is code i have tried:
string path = Server.MapPath("~/uploadaccess/Production.mdb");
string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("~/uploadaccess/Production.mdb")&";";
and also
OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path&";");
and tried this
OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("~/uploadaccess/Production.mdb"));
and this is the error i am getting:
Operator '&' cannot be applied to operands of type 'string' and 'string'
View 3 Replies
Oct 27, 2010
I am storing a custom "Organisation" object as a session variable. One of the properties of the Organisation object is "OrganisationID" (integer). I have a DataSource that requires a parameter value to run, and I want to use a SessionParameter to populate this. In a previous version, I stored the OrganisationID directly as a session variable. In that case, I could easily access it like this:
[Code]....
However, how do I now access the OrganisationID property of an "Organisation" type session variable (called "Organisation")? I have tried this, which does not seem to work: <asp:SessionParameter Name="OrganisationID" SessionField="Organisation.OrganisationID" Type="Int32" />
View 2 Replies
Feb 25, 2010
i have two sqldatasource controls. one i use to display data in textbox's ,filter'd by a select parameter in page behind code. Once checked, i want to copy this data to the other datasource ,by selecting checkbox.Then display this data in detailsview control.
At present the two datasource controls declared , render data to the page simultaneously during pageload. I want to first check data in textbox's from first source, before second datasource is rendered to screen. note, both are filtered by a page variable. i wish to leave the textbox datasource control in situ, as other controls and code depend on it.The other detailsview datasource is my problem?
View 1 Replies
Feb 10, 2010
to use a datasource from within another datasource..?
View 8 Replies
Mar 2, 2010
ASP.net SQL datasource C# code behind
I want the webpage to show a message that there is no data selected,
Instead of showing blank details view
here is a picture of blank details view:
[URL=http://img28.imageshack.us/i/errorks.jpg/][IMG]http://img28.imageshack.us/img28/4328/errorks.jpg[/IMG][/URL]
What C# code do i need to use so that, whenever I enter that page, only an error message will show up
instead of the details view ..etc.
View 3 Replies
Dec 1, 2010
im explaining this base on a test page that i have hosted as i was trying to track down my problem, i have a hosted page which i have hosted on the internet on a hosting service provider. the page has a normal gridview that is linked to a SqlDataSource. and theSqlDataSource has sql statements for selecting data, updating and deleting. They all work fine locally and even if i host them locally through IIS. but on the hosting service they down work. only the select work, which means i can view my data on the gridview but i cant manipulate it, delete and updating dont wanna work, they dont do anything. and the worse part is that im not even getting an error from them, on the grid i have enabled the autogenerate edit button and the delete, how can i make the update and delete work, or what is it that makes them not to work. the code for my test page is below
[Code]....
View 2 Replies
Feb 23, 2011
I've a listview with checkbox control in it and datasource as object data source.
I'm updating the values in listview using update method in object data source, problem is I'm not able to pass the value of checkbox checked in the update event as parameter.
View 2 Replies