Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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,

Posted

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.

Posted

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  + "";

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...