How to use a DataAdapter with stored procedure and parameter

前端 未结 9 784
名媛妹妹
名媛妹妹 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:55

        SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
            builder.DataSource = ;
            builder.UserID = ; //User id used to login into SQL
            builder.Password = ; //password used to login into SQL
            builder.InitialCatalog = ; //Name of Database
    
            DataTable orderTable = new DataTable();
    
            // stored procedute name which you want to exceute
            using (var con = new SqlConnection(builder.ConnectionString))
            using (SqlCommand cmd = new SqlCommand(, con)) 
            using (var da = new SqlDataAdapter(cmd))
            {
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                //Data adapter(da) fills the data retuned from stored procedure 
               //into orderTable
                da.Fill(orderTable);
            }
    

提交回复
热议问题