1

Please give the snippet for Visual Webpart where data is stored to SQL Database table.I'm able to store it in list but i need to store directly in SQL Server database table on submit.

1 Answer 1

3

It same as you do in C# .net.

In your button click event, define a connection string and then insert command.

For eg.

Sqlconnection con=new Sqlconnection();

con.Connectionstring="Data Source=PHANNY-PC\PHANNY; Initial Catalog=db_stuRegisterPay; Integrated Security=SSPI";
string query="insert into Persons_info(perID, latinName, gender, dob, pob, phone, passport, curAdd, status) values('" + txtID.Text + "','" + txtLatinName.Text + "','" + cbGender.Text + "'" + dTPdob.Text + txtPob.Text + "','" + txtPhone.Text + "','" + txtPassport.Text + "'" + txtCurAdd.Text + "'" + cbStatus.Text + " )";

SqlCommand cmd=new SqlCommand(query,con);
con.open();
cmd.ExecuteNonQuery();
con.close();

Code example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.