SqlConnection conn = new SqlConnection(connstring);//里面要连接字符串
string sql = string.Format("insert into table1(name,address) values('{0}','{1}')",name,address);
SqlCommand command = new SqlCommand(sql);
command.Connection = conn;
conn.Open();
command.ExecuteNonQuery();
conn.Close();
string sql = string.Format("insert into table1(name,address) values('{0}','{1}')",name,address);
SqlCommand command = new SqlCommand(sql);
command.Connection = conn;
conn.Open();
command.ExecuteNonQuery();
conn.Close();
"Initial Catalog=你的数据库名");
Conn.Open();string insertStr = "INSERT INTO 你的数据表(name,address) Values(this.name.Text.ToString(), this.address.Text.ToString())";SqlCommand insertCMD = new SqlCommand(insertStr,Conn);
insertCMD.ExecuteNonQuery();
假设引用与命名空间都已确定,自动生成
private string conn ="server=.;uid=sa;pwd=;database=data1";
private string str="select * from table1";
SqlConnection SqlConn = new SqlConnection(conn);
SqlDataAdapter Sqlad = ndw SqlDataAdapter(str,conn);
DataSet DS = new DataSet;
Sqlad.fill(DS,"table1");
string text1 = textBox1.text,text2 = textBox2.text;
string sqltext="insert table (name,address) values ('"+text1+"','"+text2+"')";
SqlConn.open();
SqlCommand Sqlcmd = ndw SqlCommand(sqltext,SqlConn);
Sqlcmd.ExecuteNonQuery();
SqlConn.Close();