hi... i want to insert data in table this is my code:
public partial class addcustomer : Form
{
//query string
string q = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|db1.mdf;Integrated Security=True;User Instance=True";
SqlConnection objconnection;
public addcustomer()
{
InitializeComponent();
objconnection = new SqlConnection(q);
}
private void btnadd_Click(object sender, EventArgs e)
{
objconnection.Open();
SqlCommand comm = new SqlCommand("insert into customers values(@cid,@cname,@contact,@city)", objconnection);
comm.Parameters.AddWithValue("@cid", 10);
comm.Parameters.AddWithValue("@cname", txtname.Text.ToString());
comm.Parameters.AddWithValue("@contact", txtcont.Text.ToString());
comm.Parameters.AddWithValue("city", txtcity.Text.ToString());
comm.ExecuteNonQuery();
objconnection.Close();
MessageBox.Show("Record Added");
}
}
|
at run time i added data no error found bt data are not inserted into table..
when i try to load data from dataset to datagrid i found connection is not establishd.
how to write querystring?
Dipa AhujaPosted Jan 21, 2010, 5:09 AM
my problem was query string i wrote querystring like
Sam HobbsPosted Jan 19, 2010, 4:45 PM