ADO.Net SQL Update

  • Thread starter Thread starter Sam
  • Start date Start date
S

Sam

I want to perform SQL Update via ADO.Net but encounter error message.

Coding
-------
Dim okcon As New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim updatecmd As New SqlCommand()

updatecmd.CommandText = "Update F0902 Set amount = gbawtd"
updatecmd.Connection = okcon
okcon.Execute()

Please guide me the correct method of ADO.Net SQL Update based above coding.

Thanks.
 
Hi Sam,

What's the error?
Try embedding gbawtd into single quotes: 'gbawtd'.
 
Compiler Error Message: BC30456: 'ExecuteNonQuery' is not a member of
'System.Data.SqlClient.SqlConnection'.
 
Compiler Error Message: BC30456: 'ExecuteNonQuery' is not a member of
'System.Data.SqlClient.SqlConnection'.
 
Compiler Error Message: BC30456: 'ExecuteNonQuery' is not a member of
'System.Data.SqlClient.SqlConnection'.

Ah - now we're getting somewhere. That error is, as you might imagine,
telling you that ExecuteNonQuery is not a method of a SqlConnection object,
which is correct - it's a method of a SqlCommand object. I take it you're
not using Visual Studio.Net...?

String strConnectionString = "<connection string to SQL Server>";
String strSQL = "<SQL to perform the write>";

SqlConnection objSqlConnection = new SqlConnection(strConnectionString);
SqlCommand objSqlCommand = new SqlCommand(strSQL, objSqlConnection);
objSqlCommand.Connection.Open();
int intRowsAffected = objSqlCommand.ExecuteNonQuery();
 
Back
Top