如何在DataSet方法中插入参数
下面就是我写的一个DataSet方法
public DataSet DisCustLanguage(string fst_language)
{
SqlConnection myConn=new SqlConnection(Connstr.ConnectionString);
DataSet ds = new DataSet();
try
{
SqlDataAdapter command = new SqlDataAdapter("Display_Cust_languages", myConn);
command.SelectCommand.CommandTimeout = 1000;
command.Fill(ds, "ds");
SqlParameter Param;
Param=new SqlParameter("@fst_language",SqlDbType.NVarChar,50);
Param.Value=fst_language;
mycmd.Parameters.Add(Param);
mycmd.CommandType=CommandType.StoredProcedure;
}
catch (
System.Data.SqlClient.SqlException e)
{
throw(e);
}
finally
{
if(myConn.State==ConnectionState.Open)
{
myConn.Close();
}
}
return ds;
}
上面就是我所写的方法,现在的问题是不知道如何在存储过程中所需的参数传进去
报错:过程 'Display_Cust_languages' 需要参数 '@fst_laguage',但未提供该参数。
谢谢大家了!
------解决方案--------------------
楼主写的有点问题,我修改了一下:
C# code
public DataSet DisCustLanguage(string fst_language)
{
SqlConnection myConn=new SqlConnection(Connstr.ConnectionString);
DataSet ds = new DataSet();
try
{
SqlCommand command =new SqlCommand("Display_Cust_languages", myConn);
command.CommandType=CommandType.StoredProcedure;
SqlParameter Param;
Param=new SqlParameter("@fst_language",SqlDbType.NVarChar,50);
Param.Value=fst_language;
command.Parameters.Add(Param);
myConn.Open();
SqlDataAdapter myda = new SqlDataAdapter();
myda.SelectCommand=command
myda.SelectCommand.CommandTimeout = 1000;
myda.Fill(ds, "ds");
}
catch (System.Data.SqlClient.SqlException e)
{
throw(e);
}
finally
{
if(myConn.State==ConnectionState.Open)
{
myConn.Close();
}
}
return ds;
}