标准表达式中数据类型不匹配(aspnet连接excel时)c#
usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingS...
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class djks : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void butCancel_Click(object sender, EventArgs e)
{
this.tbCardNumber.Text = " ";
}
protected void butSubmit_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("kscj.xls") + ";" + "Extended Properties=Excel 8.0;");
conn.Open();
if (ddlIDStyle.Text == "准考证号")
{
OleDbCommand cmd = new OleDbCommand("select * from djks where zkzh=" + this.tbCardNumber.Text, conn);
OleDbDataAdapter oleda = new OleDbDataAdapter();
oleda.SelectCommand = cmd;
DataSet ds = new DataSet();
oleda.Fill(ds, "exceltab");
dg.DataSource = ds.Tables[0].DefaultView;
dg.DataBind();
conn.Close();
conn = null;
}
else
{
OleDbCommand cmd = new OleDbCommand("select * from djks where sfzh=" + this.tbCardNumber.Text, conn);
OleDbDataReader oledr = cmd.ExecuteReader();
while (oledr.Read())
{
labContent.Text += "你的笔试成绩是" + oledr.GetString(12) + " " ;
}
oledr.Close();
}
}
}
两种方法都不对,excel中字段是常规,正常就是用字符就可以啊,但是这个就是不可以,大家看看啊!!!!
哎呀,自己解决了,郁闷,太大意了
OleDbCommand cmd = new OleDbCommand("select * from djks where sfzh="'+ this.tbCardNumber.Text"'", conn); 这句落下了几个符号.ok了!! 展开
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class djks : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void butCancel_Click(object sender, EventArgs e)
{
this.tbCardNumber.Text = " ";
}
protected void butSubmit_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("kscj.xls") + ";" + "Extended Properties=Excel 8.0;");
conn.Open();
if (ddlIDStyle.Text == "准考证号")
{
OleDbCommand cmd = new OleDbCommand("select * from djks where zkzh=" + this.tbCardNumber.Text, conn);
OleDbDataAdapter oleda = new OleDbDataAdapter();
oleda.SelectCommand = cmd;
DataSet ds = new DataSet();
oleda.Fill(ds, "exceltab");
dg.DataSource = ds.Tables[0].DefaultView;
dg.DataBind();
conn.Close();
conn = null;
}
else
{
OleDbCommand cmd = new OleDbCommand("select * from djks where sfzh=" + this.tbCardNumber.Text, conn);
OleDbDataReader oledr = cmd.ExecuteReader();
while (oledr.Read())
{
labContent.Text += "你的笔试成绩是" + oledr.GetString(12) + " " ;
}
oledr.Close();
}
}
}
两种方法都不对,excel中字段是常规,正常就是用字符就可以啊,但是这个就是不可以,大家看看啊!!!!
哎呀,自己解决了,郁闷,太大意了
OleDbCommand cmd = new OleDbCommand("select * from djks where sfzh="'+ this.tbCardNumber.Text"'", conn); 这句落下了几个符号.ok了!! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询