943,527 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 19770
  • ASP.NET RSS
Jan 21st, 2009
0

insert query in c#

Expand Post »
sql Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
sonakrish is offline Offline
34 posts
since Dec 2008
Jan 21st, 2009
0

Re: insert query in c#

Click to Expand / Collapse  Quote originally posted by sonakrish ...
"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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
snehachoudhary is offline Offline
2 posts
since Jan 2009
Jan 21st, 2009
0

Re: insert query in c#

sql Syntax (Toggle Plain Text)
  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.
Reputation Points: 16
Solved Threads: 18
Junior Poster
Aneesh_Argent is offline Offline
104 posts
since Dec 2008
Jan 22nd, 2009
0

Re: insert query in c#

You should also stear away from inserting code just like that. Look into adding parameters:

ASP.NET Syntax (Toggle Plain Text)
  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.
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007
Dec 10th, 2009
0
Re: insert query in c#
sonakrish how do i insert Radio box value into the access database. for example, S=Small, M=Medium, or L=Large.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
indianj is offline Offline
2 posts
since Dec 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: SilverLight
Next Thread in ASP.NET Forum Timeline: How to create blogs in ASP.net C# home page





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC