.net - SqlCommand.ExecuteScalar - Specify A Particular Data Item?

Jun 1, 2011

I have a Stored Procedure which returns 10 columns of data. Using cmd.ExecuteScalar() returns the value of the 1st column from the 1st record. How can I change this so that I can return different columns, by specifying their alias/dataitem name?

I want to be able to do something like: Dim FirstName as String = cmd.ExecuteScalar("FirstName")

View 4 Replies


ADVERTISEMENT

Sqlcommand.ExecuteScalar Return Dbnull?

Apr 17, 2009

i tried this sqlcommand select max(food) from foods and i tried this dim x as double=cdbl(cmd.executescalar)and it throws the the exception {System.Invalid CastException}because the food table is empty and the max(food) is null how can i fix that because i want to take the value and add one to it so do i need to catch the error or try another conversion option?

View 2 Replies

Pull DataList Item Into SqlCommand Insert Statement?

Jun 15, 2009

I have a datalist that returns multiple entries and I need to insert values via an OnClick command for a button I have with each entry. Problem is it's saying that a label I have in the datalist is not declared, in particular the MyLabel.Text from my Insert statement below.Can someone show me with code how I can declare this label or is it even possible? When I put the label outside of the datalist, everything works fine but when it's inside it says it's not declared. [code]...

View 5 Replies

Possible To Run An SQL Script With System.Data.Sql.SqlCommand?

Oct 23, 2009

After the SQL Publishing Wizard has generated a database script I would like to know if it would be possible to execute the whole SQL script using the SqlCommand object, to recreate the database all over again, in case anything goes wrong?

View 8 Replies

Asp.net - SQL Exception When Using ExecuteScalar In VS2010?

Nov 30, 2011

I am working on a login page for an asp.net application. I'm making my own login and everything is working so far: I get a connection, the query is asking to return Count from the table where the username and password match the username password in the table.

[Code]...

View 1 Replies

Form Execution Stop After ExecuteScalar

Nov 28, 2011

It worked fine till i applicated some conditions... Now my form execution stop right after a ExecuteScalar.[code]

View 2 Replies

Asp.net - EF4 Insert In VB And Return ID Of Inserted Row Like ExecuteScalar() Does

Mar 15, 2012

show me how to do an insert with EF4 VB and also how to return the ID of the inserted row?This is what I have got for edit and it works.. I have seen some very confusing ways of doing selects and edits and have found that i'm most comfortable keeping it written nice like this so that I can go back and understand what I have done.

[Code]...

I want to insert a new order with an order_id and value for ExportedToOW and get the order_id back which is auto generated by the DB..

View 1 Replies

ExecuteScalar: Connection Property Has Not Been Initialized?

Nov 3, 2011

Why i got this error ?? ExecuteScalar: Connection property has not been initialized

the red section got error.

my code

Dim sql As String
Dim sql1 As String
Dim sql2 As String

[Code].....

View 6 Replies

[2008] Object Ref Not Set When Row Not Found - EXECUTESCALAR

Feb 22, 2009

I've got this

Public Function VendorIdOf(ByVal SimpleId As String) As String
Dim result As String = Nothing
Using drc As New SqlCommand("Select VendorId From Vendor_T Where SimpleId = @SimpleId", _connection)

[Code]....

"Object reference not set to an instance of an object."
Why is that? I would expect a null value to be returned if the row does not exist.

Also - out of curiosity - how come this can be written two ways?

result = drc.ExecuteScalar().ToString()

or

result = drc.ExecuteScalar.ToString

What's up with those paren's?

View 11 Replies

ADO.NET: Return Multiple Values Instead Of Only The First In An ExecuteScalar()-like Fashion

Nov 18, 2009

currently, I use this code:

[Code]...

View 10 Replies

ExecuteScalar Isn't Returning The Return Value Of A Stored Proceedure?

Jun 4, 2010

I have an sp that deletes a bunch of rows and returns the number of rows deleted...

ALTER PROCEDURE [dbo].[DeleteChangeLog]

@ChangeEntityType bigint,

@StartDate datetime,[code]......

View 12 Replies

Reciept Printing - Form Which Consist - Item Code , Item Name , Item Price , Quantity Of Item

May 25, 2012

Regarding my college project. i'm working on a sales system . i have a form which consist of all the following information( item code , item name , item price , quantity of item ) which is display using a data grid . data input by user using text box and all this information will be stored in a database(sales database) i'm using ms access 2007. the grand total will be displayed in a text box . and amount paid will be input in a text box too , my major problem now is how to i create a reciept that will have all this information of the purcase. i have a reciept button . what the next step ? i dont have any idea how to get the reciept done.

Imports System.Data.OleDb

Public Class Form5
Dim con As New OleDbConnection

[CODE].......................

View 9 Replies

Mydata = Command.ExecuteScalar - Get The Auto-ID After Inserting A Record In To A DB

Feb 3, 2011

I'm trying to get the AutoID after inserting a record in to a DB. Does this code look right as Mydata is blank afterwards?

[Code]...

View 12 Replies

Sql Server - ExecuteScalar And SqlDataAdapter.Fill Behave Different For Same Query?

Jul 8, 2011

I have a big stored procedure that I run. At the end its supposed to select a singe value to say if it succeeded or not, so I run the query as

Dim Command As New SqlCommand(SqlString, Conn)
Return Command.ExecuteScalar()

Which works. However there is an error in my stored procedure. I know its causing an error because the logic in the stored procedure rolls back the transactions, and after the Execute Scalar call, my transaction count is down to 0 and the my data hasn't changed. However no SQL exception was generated.

The strange part is, I changed the code to grab all the result sets from the SP to see if I could get more information. So I called the same SP like this,

Dim DAObj As SqlDataAdapter = New SqlDataAdapter
Dim CommandObj As SqlCommand = New SqlCommand(SQLString, Conn)
DAObj.SelectCommand = CommandObj
Dim DS As New DataSet()
DAObj.Fill(DS)

When I run this, with the exact same sql as before, executing the exact same stored procedure, this time I get an SQL exception because one of my nested SP calls was missing required parameters. So what could cause this? Why would running it one way produce an error and the other way have the error but not report it? Is the difference on purpose, or some kind of obscure bug in ADO.Net?

View 2 Replies

VB 2010 Express ExecuteScalar Method OleDb (MS Access)?

Sep 19, 2011

How do I implement the ExecuteScalar method to return the first element in a sorted dataset?

Here is my code:Imports System.Data.OleDb
Sub Dim oCmd As OleDbCommand
Dim strConn As String
Dim strQuery As String
strConn &= "Provider=Microsoft.Jet.OleDb.4.0;"

[Code]...

View 12 Replies

VS 2005 Compare A Column Present In The Access Database Using The ExecuteScalar()

Aug 16, 2009

i want to compare a column present in the access database BankAccount table with a field present in the form named as account......

[Code]...

View 18 Replies

Run 2 SqlCommand Together?

Jan 17, 2012

[code]...

Is this possible to run 2 SqlCommand together??

Because after executed somehow the 2nd inside the loop did not execute or insert data.

View 3 Replies

C# - Convert SqlCommand To T-SQL Command

Oct 15, 2010

I have an SqlCommand with parameters. Due to some external requirement (see PS), I need one T-SQL string instead, i.e., I need ... @parameter ... replaced by ... the-value-of-@parameter-encoded-correctly ... (e.g. O'Brien --> 'O''Brien', 02 Mar 2010 --> '20100302', 3.5 --> 3.5).

I know that I could home-brew such a solution quite easily, but correct escaping is tricky (make sure you get the right date and number formats, watch for quote signs in strings, etc.), and I guess that I'm not the only one needing this, so my question is:

[Code]...

View 1 Replies

Sql :: Get SqlCommand ExecuteNonQuery Result?

Aug 29, 2011

In order to check if specific user is db_owner, i excute the following query:

"select is_rolemember('db_owner', '" & p_userName & "')"

using the SqlCommand ExecuteNonQuery method.How do I get the query result?

Here is my code:
Dim com As SqlCommand = New SqlCommand(sql, m_connection)
com.ExecuteNonQuery()

[code].....

View 3 Replies

Sqlcommand Parameters Not Executing?

Aug 13, 2010

I am encountering a strange problem when attempting to execute a DELETE query agains a SQL Server table using VB.NET, SQL Command, and Parameters.

I have the following code:

Try
sqlCommand.Transaction = transaction1
sqlCommand.Connection = conn

[Code]....

View 3 Replies

Supply SqlCommand Parameter Value?

Aug 8, 2009

Below is an UpDate Statement I am practising with David Sceppa's book ADO .NET 2.0 Core Reference pages 467 - 468. I can supply the parameter values for "parameter_New" by doing something like:

da.UpDateCommand.Parameters("@OrderID_New").Value = myTextBox.Text

And so on...My problem is how to supply the value of "paramete_Old" to be able to compare before update. I gues it has to do with obtaining the Original values of the rows based on RowVersion but I don't know how to effect it.

strSQL = "UPDATE [Order Details] " & _
"SET OrderID = @OrderID_New, ProductID = @ProductID_New, " & _
"Quantity = @Quantity_New, UnitPrice = @UnitPrice_New " & _

[code]....

View 16 Replies

Using SqlClient.SqlCommand, SqlParameter, Etc?

May 19, 2010

I am experiementing with table updates and the code below gives me the following error message: "The variable named "@Processed" has already been declared... at the following code line: clsWTAdapter.Update("clsWTDataTable"). I fear that all of my code is a general mess, and I am sure there is a much better way to go about it.

Dim clsCmd As New SqlClient.SqlCommand
Dim clsCMAdapter = New SqlClient.SqlDataAdapter("SELECT * FROM CatalogMaster WHERE Processed <>-1", clsCnn)
Dim clsCMDataTable = New DataTable("CatalogMaster")

[code]....

View 6 Replies

Data Bound To ListBox - Display Two Data Items As A Single Item?

May 7, 2012

I have an Address Book project with a listbox. The listbox is bound to the database via the little arrow pop-up box in the corner of the listbox. I have the DisplayMember set to FirstName, and obviously only display the First Name of the contact in the ListBox. Is there an easy way to change it so that it displays the First and Last names? I can't change the binding because I need it to get the ID of the record selected.Here's the basis of my code...

Private Sub MainForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'CompanyDataSet.Contacts' table. You can move,

[code].....

View 1 Replies

Are Object SqlConnection And SQLCommand Disposed

May 20, 2010

[code]in this code, do the objects con and cmd get disposed because the return statement is placed before the end using statement.

View 1 Replies

Assign Date To SqlCommand Parameter?

Nov 19, 2009

sqlCmd.Parameters.Add(New SqlParameter("@DateCreated", SqlDbType.DateTime)).Value = CDate(Now)

it throws error. Kindly suggest how can I assign date to sqlcmd parameter.

View 1 Replies

Capture SQL With Parameters Substituted In (.NET - SqlCommand)?

May 19, 2010

If there an easy way to get a completed SQL statement back after parameter substitution? I.e., I want to keep a logfile of all the SQL this program runs. Or if I want to do this, will I just want to get rid of Parameters, and do the whole query the old school way, in one big string? Simple Example: I want to capture the output:

[Code]...

View 6 Replies

Create A Lookup Using SqlCommand Select

Apr 8, 2009

I am almost finished building my application. All the data need is being inputted from various locations. I have a form that is suppose to consolidate all this data into a specific format. There are 47 fields that have to be populated and/or calculated based on two fields, the Username and a date range (this part is done). I was trying to set each of the TextBoxes equal to the SQLCommand that would return the proper value, but i am not calling it correctly. Would somebody please take look, is there something i am missing, do i need to write it in a function? I have had to use the Select statement itself in a couple of filters so I'm pretty sure that is correct, but i need help getting it to run the sqlcommand.[code]

View 16 Replies

SQLCommand Insert Netstat Results

Feb 8, 2012

I have a VB.net script that runs a simulation on several machines within the domain. During this simulation, a login is initiated to an application via a web portal. After the login, the connection to a specific Citrix server (whichever is least busy) is established. At this point, I want to run a Netstat -r | find (IP Range of server farm) in command line. From what I have deduced, I probably won't be able to do what I want from the command line and everything will have to be with in the VB.net module using System.Net.NetworkInformation. I am a Citrix Administrator with a decent level of .net experience but I am having trouble with this.

View 4 Replies

SQLCommand Not Clearing Text In Loop

Mar 3, 2010

In a for each loop I am adding rows to a table for a cross reference. Using the following code:

For Each cp In pCheckPoints
If cp <> String.Empty Then
Dim insertSQL As New StringBuilder
With insertSQL
.Append("INSERT INTO [CheckpointMessage] ( ")

Without the objCommand.CommandText = String.Empty line the CommandText is appending the insertSQL but that doesn't make any sense to me because I would expect the objCommand's commandText to be empty since it is in a using block.

View 2 Replies

Trying To Update Record Via SqlCommand With .Text Value

Jun 16, 2010

I'm trying to update a record by using the following code but it's not updating it, the value stays the original database value.[code]

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved