且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Windows窗体应用程序中的存储过程从sql server绑定网格视图的数据

更新时间:2023-02-06 22:31:27

试试这个 -

Try this-
con = new SqlConnection("server=(local);database=sp;user id=sa;password =******");
           con.Open();
           cmd = new SqlCommand();
           cmd.Connection = con;
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.CommandText = "P_PB_Getall"; 
           Datatable dt = new Datatable();
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           da.Fill(dt);
           dataGridView1.DataSource = dt; 
           con.Close();





希望,它有帮助:)



Hope, it helps :)


int id = Convert.ToInt32(comboBox2.SelectedValue.ToString());
    //int idc = 100;
    DataSet ptDataset = new DataSet();
    string con = ConfigurationManager.ConnectionStrings["secaloFormulaCS"].ToString(); 
    SqlConnection sqlCon = new SqlConnection(con);
    sqlCon.Open();
    SqlCommand sqlCmd = new SqlCommand("spDispInformation", sqlCon);
    sqlCmd.CommandType = CommandType.StoredProcedure;
    sqlCmd.Parameters.AddWithValue("@id", id);
    SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
    da.Fill(ptDataset);
    dataGridView2.DataSource =  ptDataset.Tables[0];
    sqlCon.Close();


添加这个,



add this,

Datatable dt = new Datatable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
dataGridView1.DataSource = dt;
datagridview1.Bind();
con.close();