0
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection sqlcon1 = new SqlConnection(@"Data Source=PRATHISTA;Initial Catalog=CRMT;Integrated Security=True");
sqlcon1.Open();
SqlCommand cmd1 = new SqlCommand("select * from Requirement", sqlcon1);
try
{
SqlDataReader sda1 = cmd1.ExecuteReader();
while (sda1.Read())
{
string sId = sda1.GetString("Requirement_Id");
// i get the error here;
}
sda1.Close();
sqlcon1.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error:" + ex);
}
}
似乎'Requirement_Id'是' int',而不是'string'。試試'int id = sda1.GetInt32(「Requirement_Id」)'。 –
如果'sda1.GetString(「Requirement_Id」)1 null,則在分配之前檢查'!SqlReader.IsDBNull(「Requirement_Id」)'。 – Anil
您可以添加表列的數據類型嗎?可能'Requirement_Id'不是一個字符串。 –