您好我有,我會用它來填充組合框的表空值。我不知道如何做到這一點。當我運行下面的代碼我得到的錯誤:數據爲空。此方法或屬性不能被稱爲對空值。(使用組合框)
Data is Null. This method or property cannot be called on null values.
我需要幫助,我是新來的mysql
代碼:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string constring = "datasource=localhost;port=3306;username=root;password=root";
string Query = "SELECT * from database.check WHERE patientname IS NOT NULL";
MySqlConnection conDataBase = new MySqlConnection(constring);
MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
MySqlDataReader myReader;
try
{
conDataBase.Open();
myReader = cmdDataBase.ExecuteReader();
while (myReader.Read())
{
string namethestore = myReader.GetString("namethestore");
string checkername = myReader.GetString("checkername");
this.textBox65.Text = namethestore;
this.textBox66.Text = checkername;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
你可以在你面前添加Sytem.DBNull.Value的校驗值分配給Text屬性你的文本框,請參閱http://stackoverflow.com/questions/10431835/dbnull-if-statement – VMai
首先,你到底得到的異常,其次,不會簡單的空檢查做把戲嗎? – PiotrWolkowski