Click here to Skip to main content
12,697,103 members (25,178 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET ADO.NET
look this code why it doesnt work ?
string sqlc = System.Configuration.ConfigurationManager.ConnectionStrings["ChattersDB"].ConnectionString;
System.Data.SqlClient.SqlConnection sc = new    System.Data.SqlClient.SqlConnection(sqlc);
string sqlcommand = "UPDATE UserPubInf SET Name = @Name WHERE Username = 'ali'";//+ "'" + Session["UsernameSession"].ToString() + "'";
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sqlcommand, sc);
 System.Data.SqlClient.SqlParameter sp = new System.Data.SqlClient.SqlParameter("@Name", System.Data.SqlDbType.NVarChar, 50);
sp.Value = txtName.Text ;

i want to modify column by textbox named txtName .... but it doesnt work whereas when i dnt use cvariable it work as well ...
i need use variable to define my column value....
please elp
Posted 2-Oct-12 6:24am
Updated 10-Mar-13 6:38am
sjelen 2-Oct-12 12:09pm
And what is the error you get?
source.compiler 2-Oct-12 15:51pm
i dont get error... just my codes dnt work

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

In place of

System.Data.SqlClient.SqlParameter sp = new System.Data.SqlClient.SqlParameter("Name", System.Data.SqlDbType.NVarChar, 50);
sp.Value = txtName.Text ;

You can write:

source.compiler 2-Oct-12 16:08pm
i dnt know why , but it didnt work at all, if i define a string value it works but when i use a variable it doesnt work at all ... its problem is with variables :S

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 10 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100