//添加資料
private void Button1_Click(object sender, EventArgs e)
{
myconn.Open();
string ID = textBox1.Text;
string name = textBox2.Text;
string sex = textBox3.Text;
string age = textBox3.Text;
if (textBox1.Text != "")
{
string sqlstr1 = "select count(ID) as cid from mydb.customer_infoemation where ID =" + textBox1.Text;
mycom = new MySqlCommand(sqlstr1, myconn);
MySqlDataAdapter adap = new MySqlDataAdapter(mycom);
DataSet ds = new DataSet();
adap.Fill(ds);
int a = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
if (a == 0)
{
string sqlstr = " insert into mydb.customer_infoemation(ID ,name ,sex ,age) values('" + ID + "','" + name + "','" +
sex + "' ,'" + age+ "')";
mycom = new MySqlCommand(sqlstr, myconn);
int iRet = mycom.ExecuteNonQuery();
if (iRet > 0)
MessageBox.Show("插入成功");
}
else
{
MessageBox.Show("插入失敗");
}
MySQLselect();
}
myconn.Close();
}
uj5u.com熱心網友回復:
你這哪一句是 添加datagridview資料行uj5u.com熱心網友回復:
樓主最好把問題描述清楚一些,出錯?出了什么錯?有截圖嗎?哪一行代碼報的錯?轉載請註明出處,本文鏈接:https://www.uj5u.com/net/96197.html
標籤:C#
上一篇:C#報錯1061
