1 SqlConnection conn = new SqlConnection("Data Source=SHILONGWEI;Initial Catalog=Test;Integrated Security=True"); 2 SqlCommand cmd = new SqlCommand("proc_getpubstable", conn); //存储过程的名字 3 cmd.CommandType = CommandType.StoredProcedure; //指定存储过程 4 //cmd.Parameters.Add("@table_name", SqlDbType.NVarChar).Value = "userName"; 5 SqlParameter para1 = new SqlParameter("@table_name", SqlDbType.NVarChar, 50); //需要向存储过程传递的参数 6 cmd.Parameters.Add(para1); 7 para1.Value="userName"; 8 DataSet ds = new DataSet(); 9 conn.Open(); 10 SqlDataAdapter dap = new SqlDataAdapter(); 11 dap.SelectCommand = cmd; 12 dap.Fill(ds); 13 conn.Close(); 14 GridView1.DataSource = ds; 15 GridView1.DataBind();