entry level

entry level

  • NA
  • 30
  • 2.1k

where is the parameter coming from?

Jun 12 2021 2:57 PM

I have this method 

 public DataTable getStudents(SqlCommand cmd)
        {
             string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
            using (SqlConnection con = new SqlConnection(CS))
            {              
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            
            DataTable dt = new DataTable();
            cmd.Connection = con;
            da.Fill(dt);
            return dt;
        }

 

I am trying to get student information  by  id when they click on button.On button click i have this code

 int id = Convert.ToInt32(txtId.Text);
 SqlCommand cmd = new SqlCommand("select id, first_name,last_name,birthdate,gender,phone,address,picture from students where id = " + id);                      

     DataTable dt =student.getStudents(cmd);

In objectdatasource control when i  add this method on SELECT button it is asking me where you are getting cmd parameter from? I do not understand which one give ?

 

Thanks

 

 


Answers (3)