6
Contributors
5
Replies
12
Views
8 Years
Discussion Span
Last Post by sachin.ghute3
0

"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.

0
"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

0

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.

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.