为什么该程序无法获取数据 [英] Why the data is not fetching by this program
本文介绍了为什么该程序无法获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么该程序无法获取数据.我只想获取四列数据,这些数据在所有数据点中最大.
错误-索引超出范围未由用户处理
错误行是-TextBox4.Text = dRow.ItemArray.GetValue(4).ToString();
我的CS涂层下面给出了
Why the data is not fetching by this program.I want to fetch only four columns data which points is greatest among all points.
ERROR- Index Out Of Range was unhandled by user
Error Line is - TextBox4.Text = dRow.ItemArray.GetValue(4).ToString();
My CS COADING IS GIVEN BELOW
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;
public partial class Retrive_Data_From_Database_and_display_in_TextBox : System.Web.UI.Page
{
OleDbConnection con;
OleDbCommand com;
OleDbDataAdapter da;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
con = new System.Data.OleDb.OleDbConnection();
ds = new DataSet();
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/kamnagroup.mdb") + "";
string sql = "select aname,add1,photo,point from joining WHERE point=(SELECT MAX(point) FROM joining)";
da = new System.Data.OleDb.OleDbDataAdapter(sql,con);
con.Open();
da.Fill(ds,"joining");
navigatedata();
con.Close();
con.Dispose();
}
private void navigatedata()
{
DataRow dRow=ds.Tables["joining"].Rows[0];
TextBox1.Text = dRow.ItemArray.GetValue(1).ToString();
TextBox2.Text = dRow.ItemArray.GetValue(2).ToString();
TextBox3.Text = dRow.ItemArray.GetValue(3).ToString();
TextBox4.Text = dRow.ItemArray.GetValue(4).ToString();
Image1.ImageUrl = TextBox3.Text;
}
}
推荐答案
//正确的代码是.........
//Correct code is.........
private void navigatedata()
{
DataRow dRow=ds.Tables["joining"].Rows[0];
TextBox1.Text = dRow.ItemArray.GetValue(0).ToString();
TextBox2.Text = dRow.ItemArray.GetValue(1).ToString();
TextBox3.Text = dRow.ItemArray.GetValue(2).ToString();
TextBox4.Text = dRow.ItemArray.GetValue(3).ToString();
Image1.ImageUrl = TextBox3.Text;
}
< pre lang ="c#">
私有void navigationdata()
{
DataRow dRow = ds.Tables ["joining"].Rows [0];
TextBox1.Text = dRow [0] .ToString();
TextBox2.Text = dRow [1] .ToString();
TextBox3.Text = dRow [2] .ToString();
TextBox4.Text = dRow [3] .ToString();
Image1.ImageUrl = TextBox3.Text;
}
</pre>
试试这个,我确定它会起作用..:)
<pre lang="c#">
private void navigatedata()
{
DataRow dRow=ds.Tables["joining"].Rows[0];
TextBox1.Text = dRow[0].ToString();
TextBox2.Text = dRow[1].ToString();
TextBox3.Text = dRow[2].ToString();
TextBox4.Text = dRow[3].ToString();
Image1.ImageUrl = TextBox3.Text;
}
</pre>
Try this I am sure this will work.. :)
每次调用GetValue(x)
返回的值是什么,是否有效?另外,Image1.ImageUrl
中存储的值是多少?尝试使用调试器来逐步检查代码,并在检查每个值时准确查看其失败原因.仅仅说不起作用"并不是一个非常有用的注释.
What is the value returned by each call toGetValue(x)
, is it valid or not? Also what is the value stored inImage1.ImageUrl
? Try using your debugger to step through the code and check each value as you go to see exactly why it is failing. Just saying "not working" is not a very useful comment.
这篇关于为什么该程序无法获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文