C#中写入数据库的代码

string s="男"
 string sqlstring = "database=经纪机构;Trusted_Connection=yes;";
            //创建连接数据库的字符串
            SqlConnection conn = new SqlConnection(sqlstring);
            //创建数据库连接
            conn.Open();
            SqlCommand cm = new SqlCommand();
            cm.Connection = conn;
            cm.CommandText = "insert 客户(证件号,姓名,年龄,性别) values('" + textBox2.Text.Trim() + "','" + textBox1.Text.Trim() +"',"+textBox3.Text.Trim()+",'"+s+ "')";
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cm;
            DataSet ds = new DataSet();
            da.Fill(ds);
            conn.Close();
            MessageBox.Show("交易已完成!");
            this.Close();

  

posted @ 2015-12-29 10:21  $扁桃体发炎$  阅读(818)  评论(0编辑  收藏  举报