SqlParameter[] parm =
{
new SqlParameter("@CompanyId", SqlDbType.NVarChar,50),
new SqlParameter("@EndTime", SqlDbType.DateTime),
new SqlParameter("@IncludeNoCheckt", SqlDbType.Bit),
};
parm[0].Value = textBox1.Text.Trim().ToString();
parm[1].Value = null;
parm[2].Value = null;
string str = ConfigurationManager.ConnectionStrings["WindowsFormsApplication4.Properties.Settings.qinghaiConnectionString"].ToString();
SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand command = new SqlCommand();
if (parm != null)
{
foreach (SqlParameter pm in parm)
command.Parameters.Add(pm);
}
command.CommandType = CommandType.Text;
command.CommandText = "Pro_RptPersonTotal";
command.Connection = con;
SqlDataAdapter da = new SqlDataAdapter("Pro_RptPersonTotal", con);
DataTable ds = new DataTable();
da.Fill(ds);
dataGridView1.DataSource = ds;
报错:过程或函数 'Pro_RptPersonTotal' 需要参数 '@CompanyId',但未提供该参数。哪里写错了啊。看不懂。
{
new SqlParameter("@CompanyId", SqlDbType.NVarChar,50),
new SqlParameter("@EndTime", SqlDbType.DateTime),
new SqlParameter("@IncludeNoCheckt", SqlDbType.Bit),
};
parm[0].Value = textBox1.Text.Trim().ToString();
parm[1].Value = null;
parm[2].Value = null;
string str = ConfigurationManager.ConnectionStrings["WindowsFormsApplication4.Properties.Settings.qinghaiConnectionString"].ToString();
SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand command = new SqlCommand();
if (parm != null)
{
foreach (SqlParameter pm in parm)
command.Parameters.Add(pm);
}
command.CommandType = CommandType.Text;
command.CommandText = "Pro_RptPersonTotal";
command.Connection = con;
SqlDataAdapter da = new SqlDataAdapter("Pro_RptPersonTotal", con);
DataTable ds = new DataTable();
da.Fill(ds);
dataGridView1.DataSource = ds;
报错:过程或函数 'Pro_RptPersonTotal' 需要参数 '@CompanyId',但未提供该参数。哪里写错了啊。看不懂。
给command.Parameters增加这个参数
{
foreach (SqlParameter pm in parm)
command.Parameters.Add(pm);
}
这句不是增加么???
@EndTime DATETIME,
@IncludeNoCheck BIT
执行到command.CommandType = CommandType.Text;
看看command有几个参数,看是不是少了参数 '@CompanyId'。
这是3个的意思么?
{
new SqlParameter("@CompanyId", SqlDbType.NVarChar,50),
new SqlParameter("@EndTime", SqlDbType.DateTime),
new SqlParameter("@IncludeNoCheckt", SqlDbType.Bit),
};
最后一个 “,”去掉看看
SqlParameter[] parms = new SqlParameter[3]; parms[0] = new SqlParameter("@CompanyId",textBox1.Text.Trim().ToString());
parms[1] = new SqlParameter("@EndTime", null);
parms[2] = new SqlParameter("@IncludeNoCheckt", null);要是还包的话 把存储过程内容页贴出来吧
2句都要改
楼主对存储过程调用不是很熟悉啊,还是用的text的语句
parm[2].Value = DBNull.Value;
第2,3参数你传都都是null 你看看你sql语句 参数定义的 可不可以为null
不能为null。
command.CommandType = CommandType.Text改成 command.CommandType = CommandType.StoredProcedure;SqlDataAdapter da = new SqlDataAdapter(command);
这里是这样的。
还有。。最后一个参数写错了一个字母
谢谢大家。哈哈哈哈。