用`DataReder
DataVieW都可以。代码如何写?

解决方案 »

  1.   


    sqlString = "select * from table where name='"+request.QuertString["name"]+"'";
    SqlConnection conn = new SqlConnection();
    conn.ConnectionString = ".....";
    SqlCommand cmd = new SqlCommand(sqlString,conn);
    SqlDataReader reader = cmd.executeReader();
    conn.open();
    string a = reader["a"].toString();
    string b = reader["b"].toString();
    reader.Close()
    conn.close();
      

  2.   

    不行啊,老兄,我的代码是这样的
    private void Button2_Click(object sender, System.EventArgs e) {
    String strConnection="server=(local);database=telephone;uid=sa;pwd=123;";
    SqlConnection objConnection=new SqlConnection(strConnection);

    String strSqlProducts="select * where 姓名="+"'"+TextBox1.Text+"'"+"from TABLE1";

    SqlCommand cmd = new SqlCommand(strSqlProducts,objConnection);
    SqlDataReader reader=cmd.ExecuteReader(); dgProducts.DataSource=reader;
    dgProducts.DataBind();
    reader.Close();
    objConnection.Close();

    }错语提示:ExecuteReader 需要打开的并且可用的连接。该连接的当前状态是 Closed
      

  3.   

    SqlCommand cmd = new SqlCommand(strSqlProducts,objConnection);
    ==〉加上:objConnection.open(); SqlDataReader reader=cmd.ExecuteReader();
      

  4.   

    String strSqlProducts="select * where 姓名="+"'"+TextBox1.Text+"'"+"from TABLE1";
    ------------------------------------------------------------------------------
    String strSqlProducts="select * from TABLE1 where 姓名='"+TextBox1.Text+"'";