ADO.Net SQL Update

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.
 
M

Miha Markic [MVP C#]

Hi Sam,

What's the error?
Try embedding gbawtd into single quotes: 'gbawtd'.
 
M

Mark Rae

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

And what might that error message be? Please forgive my lack of psychic
ability...
 
S

Sam

Compiler Error Message: BC30456: 'ExecuteNonQuery' is not a member of
'System.Data.SqlClient.SqlConnection'.
 
S

Sam

Compiler Error Message: BC30456: 'ExecuteNonQuery' is not a member of
'System.Data.SqlClient.SqlConnection'.
 
M

Mark Rae

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();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top