我从数据库中检索数据时遇到错误 [英] i am getting error while retrieving data from database
本文介绍了我从数据库中检索数据时遇到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
protected void Submitbtn_Click(object sender,EventArgs e)
{
string connection_string = @Provider = Microsoft.Jet .OLEDB.4.0;数据源= C:\ HILProject\project4 \ App_Data \ adminmin.mdb;
使用(OleDbConnection cn = new OleDbConnection(connection_string))
{
cn.Open();
String str =select * from BasicDtl_tbl where UserName =+ usertxt.Text +;
OleDbCommand cmd = new OleDbCommand(str,cn);
// cmd.Connection = cn;
OleDbDataAdapter ad = new OleDbDataAdapter(cmd);
System.Data.DataSet ds = new System.Data.DataSet();
ad.Fill(ds);
Nattxt.Text = ds.Tables [0] .Rows [0] .ItemArray [2] .ToString();
apldposttxt.Text = ds.Tables [0] .Rows [0] .ItemArray [3] .ToString();
cn.Close();
}
}
显示错误
在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息。
一个页面只能有一个服务器端的Form标记。
解决方案
一个页面只能有一个服务器端表单标签
在查询中添加适当的引号
String str = 从BasicDtl_tbl中选择*,其中UserName =' + usertxt.Text + ';
您的页面有两个表单标签,runat =server
或您的母公司和内容页面都有的表单标签runat =server
所以删除额外的表格标签.. :))
protected void Submitbtn_Click(object sender, EventArgs e) { string connection_string = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\HILProject\project4\App_Data\adminlog.mdb"; using (OleDbConnection cn = new OleDbConnection(connection_string)) { cn.Open(); String str = "select * from BasicDtl_tbl where UserName=" + usertxt.Text + ""; OleDbCommand cmd = new OleDbCommand(str,cn); // cmd.Connection = cn; OleDbDataAdapter ad = new OleDbDataAdapter(cmd); System.Data.DataSet ds = new System.Data.DataSet(); ad.Fill(ds); Nattxt.Text = ds.Tables[0].Rows[0].ItemArray[2].ToString(); apldposttxt.Text = ds.Tables[0].Rows[0].ItemArray[3].ToString(); cn.Close(); } }
error shown is
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
A page can have only one server-side Form tag.
解决方案
A page can have only one server-side Form tag
add appropriate quotes in the query
String str = "select * from BasicDtl_tbl where UserName='" + usertxt.Text + "'";
Either your page has two form tag withrunat="server"
or your masterpage and contentpage both has form tag withrunat="server"
so remove extra form tag.. :)
这篇关于我从数据库中检索数据时遇到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文