5 Replies - 2689 Views - Last Post: 09 February 2013 - 11:04 AM Rate Topic: -----

#1 maheshkumar1228  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 20-December 12

task: to retrieve data from access file to textbox1 on button click

Posted 04 February 2013 - 04:41 AM

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();
    }
}




Is This A Good Question/Topic? 0
  • +

Replies To: task: to retrieve data from access file to textbox1 on button click

#2 maheshkumar1228  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 20-December 12

Re: task: to retrieve data from access file to textbox1 on button click

Posted 04 February 2013 - 04:48 AM

View Postmaheshkumar1228, 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
Was This Post Helpful? 0
  • +
  • -

#3 rgfirefly24  Icon User is online

  • D.I.C Lover
  • member icon


Reputation: 260
  • View blog
  • Posts: 1,415
  • Joined: 07-April 08

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?
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.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2875
  • View blog
  • Posts: 9,538
  • Joined: 12-December 12

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.
Was This Post Helpful? 0
  • +
  • -

#5 h4nnib4l  Icon User is online

  • The Noid
  • member icon

Reputation: 1174
  • View blog
  • Posts: 1,659
  • Joined: 24-August 11

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.
Was This Post Helpful? 0
  • +
  • -

#6 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

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();).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1