using System;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Documents and Settings/abby1/My Documents/Visual Studio 2008/WebSites/WebSite3/App_Data/TEST.mdb");
OleDbDataReader rdr = null;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
conn.Open();
OleDbCommand str = new OleDbCommand("select appno from final", conn);
OleDbDataReader rdr = str.ExecuteReader();
DataSet ds = new DataSet();
if (rdr.HasRows)
{
while (rdr.Read())
{
if (rdr.Read())
{
TextBox1.Text = rdr.GetValue(0).ToString();
}
s = dr.GetData();
TextBox1.Text = Convert.ToString(str);
}
}
}
catch
{
conn.Close();
}
}
private string ToString(string p)
{
throw new NotImplementedException();
}
}
5 Replies - 1313 Views - Last Post: 09 February 2013 - 11:04 AM
#1
task: to retrieve data from access file to textbox1 on button click
Posted 04 February 2013 - 04:41 AM
Replies To: task: to retrieve data from access file to textbox1 on button click
#2
Re: task: to retrieve data from access file to textbox1 on button click
Posted 04 February 2013 - 04:48 AM
maheshkumar1228, on 04 February 2013 - 04:41 AM, said:
using System;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Documents and Settings/abby1/My Documents/Visual Studio 2008/WebSites/WebSite3/App_Data/TEST.mdb");
OleDbDataReader rdr = null;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
conn.Open();
OleDbCommand str = new OleDbCommand("select appno from final", conn);
OleDbDataReader rdr = str.ExecuteReader();
DataSet ds = new DataSet();
if (rdr.HasRows)
{
while (rdr.Read())
{
if (rdr.Read())
{
TextBox1.Text = rdr.GetValue(0).ToString();
}
s = dr.GetData();
TextBox1.Text = Convert.ToString(str);
}
}
}
catch
{
conn.Close();
}
}
private string ToString(string p)
{
throw new NotImplementedException();
}
}
i am getting only oledb connection in text box
#3
Re: task: to retrieve data from access file to textbox1 on button click
Posted 04 February 2013 - 10:06 AM
What did you expect to happen on this line?
Do this for me:
Explain what your code should be doing, What errors you're getting, and anything you've tried to correct the issues. From looking at your code it is doing exactly what you told it to do.
TextBox1.Text = Convert.ToString(str);
Do this for me:
Explain what your code should be doing, What errors you're getting, and anything you've tried to correct the issues. From looking at your code it is doing exactly what you told it to do.
#4
Re: task: to retrieve data from access file to textbox1 on button click
Posted 04 February 2013 - 10:13 AM
while (rdr.Read())
{
if (rdr.Read())
You are also reading twice in succession; you don't need the IF block.
#5
Re: task: to retrieve data from access file to textbox1 on button click
Posted 04 February 2013 - 02:42 PM
I guess my earlier reply never posted...
You have a lot of strange stuff going on that makes me think you're using primarily copy/pasted code. As andrewsw pointed out, you've nested two different methods for running your reader, and placed those inside of another piece of logic to check if the reader is empty. Next, I assume you meant 's = rdr.GetData()', not dr.GetData(). Now where is 's' declared? This is C#, you can't implicitly declare variables like you can in vbscript. I hope you didn't mean to use 'str' there. You're trying to cram the results of a method whose return type is OleDbDataReader into a variable declared as an OleDbCommand, and then just calling Convert.ToString() to make it all right? I think that you have no idea what this code is supposed to be doing, which means that you are expecting us to fix it for you. If I'm wrong, I apologize, but if not, you need to do your OWN due diligence and research what you're trying to do, to do it the right way.
You have a lot of strange stuff going on that makes me think you're using primarily copy/pasted code. As andrewsw pointed out, you've nested two different methods for running your reader, and placed those inside of another piece of logic to check if the reader is empty. Next, I assume you meant 's = rdr.GetData()', not dr.GetData(). Now where is 's' declared? This is C#, you can't implicitly declare variables like you can in vbscript. I hope you didn't mean to use 'str' there. You're trying to cram the results of a method whose return type is OleDbDataReader into a variable declared as an OleDbCommand, and then just calling Convert.ToString() to make it all right? I think that you have no idea what this code is supposed to be doing, which means that you are expecting us to fix it for you. If I'm wrong, I apologize, but if not, you need to do your OWN due diligence and research what you're trying to do, to do it the right way.
#6
Re: task: to retrieve data from access file to textbox1 on button click
Posted 09 February 2013 - 11:04 AM
Try to comment TextBox1.Text = Convert.ToString(str); since str is a command object.
You are assigning value to the textbox from database (TextBox1.Text = rdr.GetValue(0).ToString();).
You are assigning value to the textbox from database (TextBox1.Text = rdr.GetValue(0).ToString();).
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote






|