there is no special syntax for writing update query in .net
it is based on the database u r using in backend...
if you simple want to write a update query... use this syntax
SqlConnection con = new SqlConnection("your conenction string here");
con.Open();
SqlCommand command = new SqlCommand("UPDATE tableName set ColumnName =@Value WHERE ID=1",con);
command.Parameters.Add("@Value", SqlDbType.VarChar).Value = "Some value to be updated";
command.ExecuteNonQuery();
con.Close();
hope this helps...
Cheers!
KK
Please mark as Answer if post helps in resolving your issue
My Site
update [QuiTry].[dbo].[qusr] set res=
case when a.qans=b.uans
then 1
else 0 END
FROM [QuiTry].[dbo].[quiz] a,[QuiTry].[dbo].[qusr] b
but then for this I have to execute it everytime after data being entered by user .
So,for this reason I thought to write it within the code of vb.net page so that it will get updated automatically and there will be no need of going back to sql query section of databse and re-executing again and again.
I wrote the above query in vb.net and with those sqlcommand and con and it doesn't show error but its not working .
So the thing is how to write the above query in .net code?
IAmateur
Member
96 Points
388 Posts
what is the syntax to write update query ?
Apr 12, 2012 02:26 PM|LINK
what is the syntax to write update query in .net?
Time to go Long way...
AZMatt
Star
10622 Points
1893 Posts
Re: what is the syntax to write update query ?
Apr 12, 2012 02:29 PM|LINK
Here is a good tutorial for this...
http://www.asp.net/web-forms/tutorials/data-access/accessing-the-database-directly-from-an-aspnet-page/inserting-updating-and-deleting-data-with-the-sqldatasource-cs
Matt
mm10
Contributor
6395 Points
1182 Posts
Re: what is the syntax to write update query ?
Apr 12, 2012 02:29 PM|LINK
In T-SQL it is
UPDATE [Table] SET [Column]=Value WHERE [Column] = IdOfColumnOrSomeOtherCondition
Rion William...
All-Star
26980 Points
4465 Posts
Re: what is the syntax to write update query ?
Apr 12, 2012 02:29 PM|LINK
If you are writing a SQL Update Query within .NET - you would use the traditional SQL syntax:
Actual Usage:
SqlConnection sqlConnection = new SqlConnection ("Your Connection String Information"); SqlCommand yourQuery = new SqlCommand("UPDATE yourTable SET yourColumn = yourExpression WHERE yourPredicate",sqlConnection); yourQuery.ExecuteNonQuery(); sqlConnection.Close();kedarrkulkar...
All-Star
34233 Points
5498 Posts
Re: what is the syntax to write update query ?
Apr 12, 2012 02:32 PM|LINK
there is no special syntax for writing update query in .net
it is based on the database u r using in backend...
if you simple want to write a update query... use this syntax
SqlConnection con = new SqlConnection("your conenction string here"); con.Open(); SqlCommand command = new SqlCommand("UPDATE tableName set ColumnName =@Value WHERE ID=1",con); command.Parameters.Add("@Value", SqlDbType.VarChar).Value = "Some value to be updated"; command.ExecuteNonQuery(); con.Close();hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
IAmateur
Member
96 Points
388 Posts
Re: what is the syntax to write update query ?
Apr 12, 2012 02:44 PM|LINK
I had written this in sql query database table :
update [QuiTry].[dbo].[qusr] set res=
case when a.qans=b.uans
then 1
else 0 END
FROM [QuiTry].[dbo].[quiz] a,[QuiTry].[dbo].[qusr] b
but then for this I have to execute it everytime after data being entered by user .
So,for this reason I thought to write it within the code of vb.net page so that it will get updated automatically and there will be no need of going back to sql query section of databse and re-executing again and again.
I wrote the above query in vb.net and with those sqlcommand and con and it doesn't show error but its not working .
So the thing is how to write the above query in .net code?
Time to go Long way...
Dan Bracuk
Contributor
3970 Points
1096 Posts
Re: what is the syntax to write update query ?
Apr 12, 2012 03:03 PM|LINK
This:
FROM [QuiTry].[dbo].[quiz] a,[QuiTry].[dbo].[qusr] b
results in a cartesian join which is probably not your intent.
IAmateur
Member
96 Points
388 Posts
Re: what is the syntax to write update query ?
Apr 12, 2012 03:07 PM|LINK
@Dan
Its working correctly in sql query section but I want to do it .net code.
Time to go Long way...
SubaAberdeen
Member
24 Points
21 Posts
Re: what is the syntax to write update query ?
Apr 12, 2012 03:34 PM|LINK
UPDATE Employee
SET name='"+txtName.text.ToString()+"', DOB='"+txtDOB.Text.toString()+"'
WHERE emp_ID= request.Querystring.ID
IAmateur
Member
96 Points
388 Posts
Re: what is the syntax to write update query ?
Apr 12, 2012 03:37 PM|LINK
SubaAberdeen
Kindly read my previous post
Time to go Long way...