我是c#的新手,當我運行我的C#代碼時出現此錯誤。請任何人給我解決這個一個有效的方法..在c#中的運行時錯誤 - 在mscorlib.dll中發生未處理的類型爲'System.FormatException'的異常mscorlib.dll
Run-time error - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
private void textBox13_TextChanged_1(object sender, EventArgs e)
{
conn.Open();
MySqlCommand comm1 = new MySqlCommand("SELECT `l_points` FROM `customer` WHERE `ph_no` ='" + Convert.ToInt32(textBox13.Text) + "'", conn);
//MySqlDataReader mdr = comm1.ExecuteReader();
//MessageBox.Show(comm1.ExecuteScalar().ToString());
//textBox12.Text = comm1.ExecuteScalar().ToString();
MySqlDataReader red = comm1.ExecuteReader();
if(red.Read())
{
textBox12.Text = red.GetString("l_points");
conn.Close();
conn.Open();
//int x = (Convert.ToInt32(textBox12.Text) - Convert.ToInt32(textBox2.Text)) +Convert.ToInt32 (textBox10.Text);
//string qry = "Update customer SET l-points = x where ph_no= '"+Convert.ToInt32(textBox13.Text)+"'";
//////
MySqlDataAdapter da = new MySqlDataAdapter("Update customer SET l_points = '"+((Convert.ToInt32(textBox12.Text) - Convert.ToInt32(textBox2.Text))
+Convert.ToInt32 (textBox10.Text))+"' where ph_no= '" + Convert.ToInt32(textBox13.Text) + "'", conn);
da.SelectCommand.ExecuteNonQuery();
MessageBox.Show("update sucess!!!!!!");
}
conn.Close();
//double bal = Convert.ToDouble(textBox7.Text) * 0.01;
////double bal = 1000;
////MessageBox.Show(textBox7.Text);
//textBox10.Text = bal.ToString();
}
將代碼粘貼在這裏,你得到這個錯誤。 – Amit
也要小心SQL注入,儘可能使用參數。 – vasek