Similar Threads:
1.ExecuteScalar method sometimes work, sometimes doesn't
Hi,
I've got some weird behavior happening within one of the datamappers. It
all has to do with inserting a new row, and returning the Id of the row
being entered.
Here is what the code looks like that is getting "Object reference not set
to an instance ..." run-time error:
string ateId = cm.ExecuteScalar().ToString(); -----------
this line crashes
None of the parameters are null, nor do they appear to have any illegal data
inside of them. The above code inserts a row into the AuditTrailEntry
table.
On the other hand, this code inserts a new jobStep row, and doesn't cause
any errors:
if (storedProcedure == "updateJobStep") //use this if update
cm.ExecuteNonQuery(); // no return value needed
else
{
string jobStepId = cm.ExecuteScalar().ToString(); //insert new
jobStep, get id of new row
js.Id = Convert.ToInt16(jobStepId);
}
Does anyone see a problem with this code, or know why it doesn't work?
TIA, Randy
2.Confused with ExecuteScalar method of SQLCommand
Hi,
I have one stored procedure in SQL server in which i have written one
insert statement. Now in my cs file i pass the parameters require to execute
that stored procedure and finaly by mistaken I used command.ExecuteScalar
instead of command.ExecuteNonQuery. Surprisingly i am able to insert the data
in table. Can anyone please tell me how i am able to insert data using
ExecuteScalar of SQLCommand class.
Help is really appriciated.
Thx in advance
3.oracleclient and executescalar
Why this code doesn't function?
Dim oraCn As OracleConnection, oraCmd As OracleCommand
Dim ris As Object
oraCn = New OracleConnection("user id=user;data source=pcname;password=pwd")
oraCn.Open()
oraCmd = oraCn.CreateCommand
oraCmd.CommandText = "SELECT Tabe1.Campo1 From Tabe1;"
ris = oraCmd.ExecuteScalar
I try to use ExecuteOracleScalar too, but it doesn't function, I have a
"System.Error"
tnx
4.Can't get oleDbCommand to ExecuteScalar more than once
While debugging a stored procedure in a test application, I was doing
this against an MS Access database in a button click event:
oleDbCommand1.Parameters[0].Value = textBox.Text;
object dude = oleDbCommand1.ExecuteScalar();
if ( dude == null )
{
MessageBox.Show("no result from stored proc");
}
else
{
txtAnother.Text = dude.ToString();
}
This works fine the first time it is called and any subsequent times as
long as the parameter passed in from the textBox doesn't change, but if
I change it to another string that should give me a valid result from
the stored procedure, the result of ExecuteScalar is null.
If I restart the application and use that new string from the beginning,
I get a valid result.
The connection remains open, and I'm not changing parameter collection
of the command object.
What the hell?
5.sqlCommand.ExecuteScalar problem on return value
Hi
"Select UserId from users where userid = 2"
How come it return Undefined value if the select doesn't return any result?
How can I know if the select succeded or not?
Thanks,
Ronen
6. Using ExecuteScalar on ,Net Framework 1.1
7. ExecuteScalar don't return the corrent Int value.
8. ExecuteScalar closes connection