SQL操作,说数据类型不匹配,请帮忙!

hooohooooooo 2006-05-24 09:19:55
出错行显示在Fill的时候.
id 是数据库中的一个自动编号字段.

Int32 se = Convert.ToInt32 (Session["id"]);

//Response.Write(se);
con.Open();
ds = new DataSet();
string sql = "select id ,title,content,ram,overtime,Tpoint from question where id='" + se + "'";
//com = new System.Data.OleDb.OleDbCommand(sql, con);
da = new System.Data.OleDb.OleDbDataAdapter(sql, con);
da.Fill(ds, "question");

Label1.Text = Server .HtmlDecode ( ds.Tables["question"].Rows[0][2].ToString());
Label3.Text = Server.HtmlDecode(ds.Tables["question"].Rows[0][0].ToString());
Label5.Text = Server.HtmlDecode(ds.Tables["question"].Rows[0][1].ToString());
Label7.Text = Server.HtmlDecode(ds.Tables["question"].Rows[0][4].ToString());
Label9.Text = Server.HtmlDecode(ds.Tables["question"].Rows[0][3].ToString());
Session ["point"]=Server.HtmlDecode(ds.Tables["question"].Rows[0][5].ToString ());

da.Dispose();
con.Close();
...全文
268 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
Knight94 2006-05-24
  • 打赏
  • 举报
回复
用如下这条语句进行查询。
string sql = "select [id] ,[title],[content],[ram],[overtime],[Tpoint] from [question] where [id]=" + se.ToString();
hooohooooooo 2006-05-24
  • 打赏
  • 举报
回复
数据库:
string strcon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("App_Data/noi.mdb") + ";User Id=admin;Password=;";
con = new OleDbConnection(strcon);

错误提示:

System.Data.OleDb.OleDbException: 标准表达式中数据类型不匹配。 在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) 在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) 在 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) 在 System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) 在 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) 在 System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) 在 System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) 在 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) 在 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) 在 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) 在 questionN.bind() 位置 d:\Visual Studio 2005\NOI\questionN.aspx.cs:行号 56
Knight94 2006-05-24
  • 打赏
  • 举报
回复
数据库是什么,报什么错
vcforeverya 2006-05-24
  • 打赏
  • 举报
回复
对,用字符类型
hooohooooooo 2006-05-24
  • 打赏
  • 举报
回复
转为string也一样,还是数据类型不匹配.
lcddjyy 2006-05-24
  • 打赏
  • 举报
回复
应该把数字转化为字符型的.
aspgreener 2006-05-24
  • 打赏
  • 举报
回复
楼上正解!
Knight94 2006-05-24
  • 打赏
  • 举报
回复
change
string sql = "select id ,title,content,ram,overtime,Tpoint from question where id='" + se + "'";
with
string sql = "select id ,title,content,ram,overtime,Tpoint from question where id=" + se.ToString() + "";
hooohooooooo 2006-05-24
  • 打赏
  • 举报
回复
string sql = "select id ,title,content,ram,overtime,Tpoint from question where id=" + se + "";
这样也可以成功的.
hooohooooooo 2006-05-24
  • 打赏
  • 举报
回复
非常感谢,请问大侠为什么要加[]呢?
wpfonline 2006-05-24
  • 打赏
  • 举报
回复
楼上 winner2050
正解 只有字符行的才加‘’
winner2050 2006-05-24
  • 打赏
  • 举报
回复
这么写ID号有英文的'就被任务是字符了。而ID字段是INT的
string sql = "select id ,title,content,ram,overtime,Tpoint from question where id='" + se + "'";

你应该这样写
string sql = "select id ,title,content,ram,overtime,Tpoint from question where id=" + se;

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧