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();
相關文章
相關標籤/搜索