954,577 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

insert query in c#

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#?

sonakrish
Light Poster
34 posts since Dec 2008
Reputation Points: 10
Solved Threads: 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#?


I am unable to understand the motive the query.Give wat you want to do.

snehachoudhary
Newbie Poster
2 posts since Jan 2009
Reputation Points: 10
Solved Threads: 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

Aneesh_Argent
Junior Poster
104 posts since Dec 2008
Reputation Points: 16
Solved Threads: 18
 

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

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


This prevents SQL Injection.

SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
 

sonakrish how do i insert Radio box value into the access database. for example, S=Small, M=Medium, or L=Large.

indianj
Newbie Poster
2 posts since Dec 2005
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You