insert query in c#

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2008
Posts: 30
Reputation: sonakrish is an unknown quantity at this point 
Solved Threads: 1
sonakrish sonakrish is offline Offline
Light Poster

insert query in c#

 
0
  #1
Jan 21st, 2009
  1. INSERT INTO desg VALUES(" & Val(txtsno.Text) & ",'" & Trim(txtdesg.Text) & "'," & Val(txtbasic.Text) & ");
this how i used for inserting data to my access table in vb code.
how to do in c#?
Last edited by peter_budo; Jan 21st, 2009 at 7:55 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 2
Reputation: snehachoudhary is an unknown quantity at this point 
Solved Threads: 1
snehachoudhary snehachoudhary is offline Offline
Newbie Poster

Re: insert query in c#

 
0
  #2
Jan 21st, 2009
Originally Posted by sonakrish View Post
"insert into desg values(" & Val(txtsno.Text) & ",'" & Trim(txtdesg.Text) & "'," & Val(txtbasic.Text) & ");" this how i used for inserting data to my access table in vb code.
how to do in c#?
I am unable to understand the motive the query.Give wat you want to do.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 104
Reputation: Aneesh_Argent is an unknown quantity at this point 
Solved Threads: 18
Aneesh_Argent Aneesh_Argent is offline Offline
Junior Poster

Re: insert query in c#

 
0
  #3
Jan 21st, 2009
  1. "INSERT INTO desg VALUES(" + txtsno.TEXT + ", " + txtdesg.TEXT +", " + txtbasic.TEXT + ");";

You dont need to worry about Trim and Val functions here. Trim will happen automatically and Val is irrelevant here
Last edited by peter_budo; Jan 21st, 2009 at 7:55 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: insert query in c#

 
0
  #4
Jan 22nd, 2009
You should also stear away from inserting code just like that. Look into adding parameters:

  1. SqlCommand comm = new SqlCommand("INSERT INTO desg VALUES (@txtsno, @txtdesg, @txtbasic)", connection);
  2. comm.Parameters.AddWithValue("@txtsno", txtsno.Text.Trim());
  3. comm.Parameters.AddWithValue("@txtsno", txtdesg.Text.Trim());
  4. comm.Parameters.AddWithValue("@txtsno", txtbasic.Text.Trim());

This prevents SQL Injection.
I answer pm's.
I answer questions.
I answer quickly.
I answer.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC