数据库查询主码存在与否
如果存在主码则弹框,不存在则继续。
SqlCommand one = new SqlCommand("select version from t_version_base where version='" + textBox2.ToString() + "'", conn);
one.CommandType = CommandType.Text;
one.ExecuteNonQuery();
SqlDataReader dr = null;
dr = one.ExecuteReader();
while (dr.Read())
{
if (dr["version"] != null)
{
string str = dr["version"].ToString();
if (str.ToString() == textBox2.ToString())
{
MessageBox.Show("hhhhhhhhhhhhhhhhhhh");
} dr.Close();
}
}
{
if (dr["version"] != null)
{
string str = dr["version"].ToString();
//str本来就是string,不同ToString()了,取文本框的值用Text属性
if (str.ToString() == textBox2.Text)
{
MessageBox.Show("hhhhhhhhhhhhhhhhhhh");
} dr.Close();
}
}
[其他解释]
对。是这样比较的。。。。。。。。。。