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

Recommended Answers

All 5 Replies

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

"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

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.

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

INSERT INTO user_login (user_Name) VALUES (@user_Name)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.