小的刚学C#,遇到一个问题,我在做一个登录页面遇到个问题。我如何知道我查寻的有没有结果呢?
代码如下: private void Button1_Click(object sender, System.EventArgs e)
{
name=this.TextBox2.Text;
password=this.TextBox3.Text;
strconn="select * from id where idname='"+ name + "' and idpassword = '" +password +"'";
this.TextBox3.Text=strconn;//select * from id where idname='admin' and idpassword='admin'
myconn=new System.Data.SqlClient.SqlConnection("server=localhost;Trusted_Connection=true;database=log");
mycomm=new System.Data.SqlClient.SqlDataAdapter(strconn,myconn);
TextBox2.Text=mycomm.TableMappings; }

解决方案 »

  1.   

    好象很乱
    SqlCommand sqlSelect = new SqlCommand("SELECT * from id where idname=@userid" +
    "and idpassword=@password")
    sqlAlter.Parameters.Add(new SqlParameter("@userid",SqlDbType.VarChar,8)).Value = this.TextBox2.Text.Trim();
    sqlAlter.Parameters.Add(new SqlParameter("@password",SqlDbType.VarChar,16)).Value = this.TextBox3.Text;.Trim();myconn=new System.Data.SqlClient.SqlConnection("server=localhost;Trusted_Connection=true;database=log");
    mycomm=new System.Data.SqlClient.SqlDataAdapter(strconn,myconn);DataSet ds = new DataSet();
    mycomm.Fill(ds);
    DataGrid dataGrid = new DataGrid();
    dataGrid.DataSource = ds.Tables[0];随手写的,大致这样,你整理一下吧,呵呵
      

  2.   

    这位老兄写串了 呵呵,你的程序里哪儿来的strconn,串到楼主的定义里去了。你的是sqlSelect