我做了一个查询!页面上有一个文本框和按钮!我数据库里有一张表stduent!
里面有字段id int(4),name nvrchar(30) 30,age nvrchar(4),addres nvrchar(100),我查询按钮是这样写的!
private void BtSelect_Click(object sender, System.EventArgs e)
{
SqlConnection conn=new SqlConnection("server=localhost;user id=sa;database=pubs");
DataSet ds = new DataSet();
try
{
string Sql="select * from student where id like '%'+@cp_id+'%'";

SqlDataAdapter  da  = new  SqlDataAdapter(Sql,conn);da.SelectCommand.CommandType = CommandType.Text;da.SelectCommand.Parameters.Add(new SqlParameter("@cp_id", SqlDbType.Int));
da.SelectCommand.Parameters["@cp_id"].Value =this.txtId.Text.Trim();da.Fill(ds,"student");
this.DataGrid1.DataSource = ds.Tables["cp_info"].DefaultView;
this.DataGrid1.DataBind();
conn.Close();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
conn.Close();
}
}查询出来以后把数据绑定到DataGrid上!但是到这步总是报错!小弟我不知道怎么把TextBox里的字符串转换成Int型然后可以查询!
da.SelectCommand.Parameters.Add(new SqlParameter("@cp_id", SqlDbType.Int));请给代码示例!C#语言!