ALTER proc [dbo].[bb]
@startIndex nvarchar(20)='%1%'as
begin
select * from base_worker where worker_name like @startIndex
//连接字符串
String DBConnStr;
DataSet MyDataSet=new DataSet();
System.Data.SqlClient.SqlDataAdapter DataAdapter=new System.Data.SqlClient.SqlDataAdapter();
DBConnStr = "server=服务器名称;uid=用户名;pwd=密码;database=数据库名称";
System.Data.SqlClient.SqlConnection myConnection = new System.Data.SqlClient.SqlConnection(DBConnStr);
if (myConnection.State!=ConnectionState.Open)
{
myConnection.Open();
}
System.Data.SqlClient.SqlCommand myCommand = new System.Data.SqlClient.SqlCommand("bb",myConnection);
myCommand.CommandType=CommandType.StoredProcedure;
//添加输入查询参数、赋予值
myCommand.Parameters.Add("@startIndex", SqlDbType.VarChar);
myCommand.Parameters["@startIndex"].Value = "1%";
//添加输出参数
// myCommand.Parameters.Add("@worker_name", SqlDbType.NVarChar);
myCommand.ExecuteNonQuery();
DataAdapter.SelectCommand = myCommand;
if (MyDataSet!=null)
{
DataAdapter.Fill(MyDataSet,"table");
}
GridView1.DataSource=MyDataSet;
GridView1.DataBind();