UrKo Posted July 29, 2009 Posted July 29, 2009 HI, I have written a statement to update hits per record in DB (im using access db). However, if i add where clause i get an error "Parameter ?_1 has no default value". This is my code: protected void DataList1_Load(object sender, EventArgs e) { Label Label1 = DetailsView1.FindControl("Label1") as Label; Label hits = DataList1.FindControl("hits") as Label; TextBox TextBoxVideoId = DataList1.FindControl("TextBoxVideoId") as TextBox; string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\CenterDB.mdb"; OleDbConnection conn = new OleDbConnection(connectionString); conn.Open(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = conn; cmd.CommandText = "UPDATE VIDEO_MOJI SET hits = hits + 1 WHERE VideoId = ?"; cmd.Parameters.Add("@hits", OleDbType.Integer).Value = hits; cmd.ExecuteNonQuery(); conn.Close(); } thanks, Quote
Administrators PlausiblyDamp Posted July 29, 2009 Administrators Posted July 29, 2009 IIRC the OleDb provider doesn't support named parameters, you just add the parameters in the correct order and do not bother to specify a name. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
UrKo Posted July 29, 2009 Author Posted July 29, 2009 hi, thanks for the reply. Im new to .net so can you explain a little more of what name to specify? If i just write upade without where clause, then it updates all records in the db. Quote
UrKo Posted July 29, 2009 Author Posted July 29, 2009 ok i made it. i added this and it's working :) string getVideoId = (string)Label1.Text; getVideoId = getVideoId.Trim(); cmd.CommandText = "UPDATE VIDEO_MOJI SET hits= hits+ 1 WHERE VideoId = " + getVideoId + ""; Quote
Administrators PlausiblyDamp Posted July 30, 2009 Administrators Posted July 30, 2009 Have you tried creating the parameter and then setting it's value before adding it to the parameters collection? Also the parameters collection has a .AddWithValue method that might work. You really want to avoid concatenating strings though as this can cause all sorts of odd security risks and is generally a bad practice. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.