In reference to my question,
How to get boundfield value, or am I totally wrong?
I am trying to add update parameter to a SQLDataSource using c# instead of ASP.NET but I am getting error,
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int userID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values["userID"].ToString());
string userName = "";
string city = "";
string updateStatement = "Update myTable set userName=@userName, city=@city where userID=@userID";
foreach (DictionaryEntry entry in e.NewValues)
{
if (entry.Key == "userName")
userName = entry.Value.ToString();
if (entry.Key == "city")
city = entry.Value.ToString();
}
using (SqlDataSource ds = new SqlDataSource(ConnectionString(), updateStatement))
{
ds.UpdateParameters.Add("@userName");
ds.UpdateParameters.Add("@city");
ds.UpdateParameters.Add("@UserId");
}
gvDetails.EditIndex = -1;
BindData();
}
How can I pass values of parameters :S
ds.UpdateParameters.Add("@userName");
ds.UpdateParameters.Add("@city");
ds.UpdateParameters.Add("@UserId");
But I don't know the right syntax, can someone direct me in right direction please
You can't add parameters to
SqlDataSource
. You can addSqlCommand
instead. Try something similar like this;I think you should use an SqlCommand instead of SqlDataSource:
if you want to use SQLDataSource, then I believe the syntax is.
No '@' and you can supply the default value.