使用DataSet时遇到的问题
我首先在项目名称 recvd.xsd
中手动创建了一个具有相应 recvd.xss
的 DataSet
。在我的按钮单击事件中,我完成了以下编码。
try
{
DataSet recvd_REPORT = new DataSet();
DataTable REPORT = new DataTable();
String dd_webCofig = ConfigurationManager.ConnectionStrings["server2"].ConnectionString;
OdbcConnection ddlistconn = new OdbcConnection(dd_webCofig);
ddlistconn.Open();
REPORT = recvd_REPORT.Tables["REPORT"];
DataColumn myDataColumn = new DataColumn();
myDataColumn.DataType = typeof(System.Int32);
myDataColumn.ColumnName = "RECEIVED";
myDataColumn.ReadOnly = false;
myDataColumn.Unique = false;
// Add the Column to the DataColumnCollection.
REPORT.Columns.Add(myDataColumn);
string query = "SELECT case_no as \"RECEIVED\" from dcpanaji.Civil_t where dt_regis > '" + txtStartDate.Text + "' AND dt_regis < '" + txtEndDate.Text + "' AND court_no = " + DropDownList1.SelectedItem + "";
Response.Write(query);
OdbcCommand cmd = new OdbcCommand(query, ddlistconn);
OdbcDataReader loginMyReader = cmd.ExecuteReader();
OdbcDataAdapter adptr = new OdbcDataAdapter(query, ddlistconn);
adptr.Fill(REPORT);
ddlistconn.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
我收到的错误是
未将对象引用设置为对象的实例。
如果我从 SQL 查询中删除 as \"RECEIVED\"
并简单地执行 SQL 查询,则查询结果如下(根据用户输入而变化)
200200000452011
……,n个12位数字。
请帮助我删除关于为什么我无法绑定到数据表的错误。
我在执行 Response.Write(query); 之前收到错误,为什么会出现这个问题?
我删除了 try catch 块,现在收到错误
I have first manually created a DataSet
in my project name recvd.xsd
having corresponding recvd.xss
. On my button click event i have done the following coding.
try
{
DataSet recvd_REPORT = new DataSet();
DataTable REPORT = new DataTable();
String dd_webCofig = ConfigurationManager.ConnectionStrings["server2"].ConnectionString;
OdbcConnection ddlistconn = new OdbcConnection(dd_webCofig);
ddlistconn.Open();
REPORT = recvd_REPORT.Tables["REPORT"];
DataColumn myDataColumn = new DataColumn();
myDataColumn.DataType = typeof(System.Int32);
myDataColumn.ColumnName = "RECEIVED";
myDataColumn.ReadOnly = false;
myDataColumn.Unique = false;
// Add the Column to the DataColumnCollection.
REPORT.Columns.Add(myDataColumn);
string query = "SELECT case_no as \"RECEIVED\" from dcpanaji.Civil_t where dt_regis > '" + txtStartDate.Text + "' AND dt_regis < '" + txtEndDate.Text + "' AND court_no = " + DropDownList1.SelectedItem + "";
Response.Write(query);
OdbcCommand cmd = new OdbcCommand(query, ddlistconn);
OdbcDataReader loginMyReader = cmd.ExecuteReader();
OdbcDataAdapter adptr = new OdbcDataAdapter(query, ddlistconn);
adptr.Fill(REPORT);
ddlistconn.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
I am getting the error as
Object reference not set to an instance of an object.
If i remove as \"RECEIVED\"
from my SQL query and simply execute my SQL query than the result of my query is as follows (varies depending on user input)
200200000452011
......, n numbers of 12 digit number.
Please help me to remove the error as to why am i not able to bind to DataTable.
I am getting the error before Response.Write(query);
is executed, why is that problem?
I removed the try catch block and now i get the error as
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试
或者只是
无论如何,正确的数据集填充代码应该如下所示:
try
or just
Anyway the correct DataSet filling code should look like this:
在你的 SQL 中,而不是 \"RECIEVED\" 你是否尝试过只 RECIEVED,没有引号?
In your SQL instead of \"RECIEVED\" have you tried just RECIEVED, no quotes?
您不需要在查询中使用“RECEIVED”,您可以像下面这样使用。
You need not to use \"RECEIVED\" in the query, you can use like below.
你可以像检查一样编写查询
......
you can write query as like
check like that....