蛋蛋后小音 2019-05-07 16:41 采纳率: 0%
浏览 286

vs用户代码未识别sqlexception

protected void btn4_Click(object sender, EventArgs e)
{
SqlConnection connSelect = new SqlConnection(connStr);
SqlConnection connProc = new SqlConnection(connStr);
SqlConnection connView = new SqlConnection(connStr);
string sqlStrSelect = "select XM, XB,CONVERT(char(20),CSSJ,20) AS CSSJ,KCS from XS where XM ='"+xm.Text.Trim()+"'";
string sqlStrView = "select*from XMCJ_VIEW";
try
{
connSelect.Open();
SqlCommand myCommand = new SqlCommand(sqlStrSelect, connSelect);
SqlDataReader reader = myCommand.ExecuteReader();
if (reader.Read())
{
xm.Text = reader["XM"].ToString();
xb.SelectedValue = reader["XB"].ToString();
cssj.Text = reader["CSSJ"].ToString();
kcs.Text = reader["KCS"].ToString();
Image1.ImageUrl = "Pic.aspx?id=" + xm.Text.Trim();
Lbl_Msg.Text = "查找成功!";
}
connProc.Open();
SqlCommand proCommand = new SqlCommand();
proCommand.Connection = connProc;
proCommand.CommandType = CommandType.StoredProcedure;
proCommand.CommandText = "CJ_PROC";
SqlParameter SqlXm = proCommand.Parameters.Add("@xml", SqlDbType.Char, 8);
SqlXm.Direction = ParameterDirection.Input;
SqlXm.Value = xm.Text.Trim();
proCommand.ExecuteNonQuery();
connView.Open();
SqlDataAdapter mda = new SqlDataAdapter(sqlStrView, connView);
DataSet ds = new DataSet();
mda.Fill(ds, "XMCJ_VIEW");
GridView1.DataSource = ds;
GridView1.DataBind();
}
catch
{
Lbl_Msg.Text = "查找失败,请检查操作权限!";
}
finally
{
connSelect.Close();
connProc.Close();
connView.Close();
}

}

加断点执行后错误在于proCommand.ExecuteNonQuery();,提示错误原因为用户代码未识别sqlexception,列名“李明 ”无效。李明是数据库中的一个姓名。

  • 写回答

2条回答 默认 最新

  • threenewbee 2019-05-07 17:06
    关注

    李明 是值还是列,如果是值,那么就是你的列缺少引号。你的存储过程和sql检查下。

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog