C#如何以TEXTBOX控件中输入的内容查找数据库其他内容

查询加上条件即可。
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "server=.;database=yourdb;uid=sa;pwd=pwd";
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandText = "select regdate from yourtable where carNO=@no";
cmd.Parameters.AddWithValue("@no",textBox1.Text.Trim());
var date = cmd.ExecuteScalar();
cn.Close();
if(date!=System.DBNull.Value )
{
this.textBox2.Text = date.ToString();
}

猜你喜欢

转载自blog.csdn.net/cxu123321/article/details/85673670