How to use a DataAdapter with stored procedure and parameter

前端 未结 9 768
名媛妹妹
名媛妹妹 2020-11-30 01:05

I want to fill a DataGridView control using DataAdapter. But I don\'t know how to do it since I\'m using a stored procedure with parameter. Can someone cite an example pleas

9条回答
  •  情歌与酒
    2020-11-30 01:34

     SqlConnection con = new SqlConnection(@"Some Connection String");
     SqlDataAdapter da = new SqlDataAdapter("ParaEmp_Select",con);
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                da.SelectCommand.Parameters.Add("@Contactid", SqlDbType.Int).Value = 123;
                DataTable dt = new DataTable();
                da.Fill(dt);
                dataGridView1.DataSource = dt;
    

提交回复
热议问题