Data Bind a Text Box

Discussion in 'ASP .Net' started by Steve Bishop, Apr 30, 2004.

  1. Steve Bishop

    Steve Bishop Guest

    I can't believe how hard this has been! I'm sure it's just a matter of
    finding the right syntax for C#, but
    I can't bind a text box right now.
    In testing, I'm just trying one text box for now (TextBox3). Help
    appreciated C#. Thanks.

    Compiler Error Message: CS0029: Cannot implicitly convert type 'object'
    to 'string'
    Source Error:
    Line 34: DataView dv1 = new DataView(dtAR1);
    Line 35:
    Line 36: TextBox3.Text = dv1[0]["CustomerNumber"];
    Line 37:
    Line 38: dgAR1.DataSource = objDataSet.Tables["dtAR1"];

    <CODE>
    public void Page_Load(object sender, System.EventArgs e){

    //Connection Setup

    OdbcConnection myConn = new OdbcConnection("dsn=SOTAMAS90AUTO");

    String strSQL = "SELECT AR1.Division + AR1.CustomerNumber As
    KeyField, AR1.Division, AR1.CustomerNumber, AR1.CustomerName,
    AR1.ContactCode, AR1.City, AR1.State, AR1.ZipCode, AR1.PhoneNumber,
    ARD.Name FROM { oj ARD_SalesPersonMasterfile ARD LEFT OUTER JOIN
    AR1_CustomerMaster AR1 ON (ARD.SalesPersonNumber =
    AR1.SalesPersonCode)}";

    //DataAdapter Setup
    OdbcDataAdapter adapter = new OdbcDataAdapter(strSQL, myConn);

    //DataSet, DataAdapter & Table
    DataSet objDataSet = new DataSet();
    adapter.Fill(objDataSet, "dtAR1");

    //Set up a filter to use the text box value...
    String Filter = "CustomerNumber = 'ABF'";

    objDataSet.Tables[0].DefaultView.RowFilter = Filter;
    objDataSet.Tables["dtAR1"].DefaultView.RowFilter = Filter;

    //Create DataTable & DataView to feed single text box values on
    form.....
    DataTable dtAR1 = objDataSet.Tables["dtAR1"];
    DataView dv1 = new DataView(dtAR1);

    TextBox3.Text = dv1[0]["CustomerNumber"];

    dgAR1.DataSource = objDataSet.Tables["dtAR1"];

    dgAR1.DataBind();

    }
    <CODE>


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Steve Bishop, Apr 30, 2004
    #1
    1. Advertising

  2. Steve Bishop

    RadekP Guest

    Just cast it to string, your manually generated dataset does not have a
    schema assigned thus it makes use of general objects for column types unless
    you specify it.

    TextBox3.Text = (string) dv1[0]["CustomerNumber"];
    TextBox3.DataBind();

    Radek

    "Steve Bishop" <> wrote in message
    news:uhb$...
    > I can't believe how hard this has been! I'm sure it's just a matter of
    > finding the right syntax for C#, but
    > I can't bind a text box right now.
    > In testing, I'm just trying one text box for now (TextBox3). Help
    > appreciated C#. Thanks.
    >
    > Compiler Error Message: CS0029: Cannot implicitly convert type 'object'
    > to 'string'
    > Source Error:
    > Line 34: DataView dv1 = new DataView(dtAR1);
    > Line 35:
    > Line 36: TextBox3.Text = dv1[0]["CustomerNumber"];
    > Line 37:
    > Line 38: dgAR1.DataSource = objDataSet.Tables["dtAR1"];
    >
    > <CODE>
    > public void Page_Load(object sender, System.EventArgs e){
    >
    > //Connection Setup
    >
    > OdbcConnection myConn = new OdbcConnection("dsn=SOTAMAS90AUTO");
    >
    > String strSQL = "SELECT AR1.Division + AR1.CustomerNumber As
    > KeyField, AR1.Division, AR1.CustomerNumber, AR1.CustomerName,
    > AR1.ContactCode, AR1.City, AR1.State, AR1.ZipCode, AR1.PhoneNumber,
    > ARD.Name FROM { oj ARD_SalesPersonMasterfile ARD LEFT OUTER JOIN
    > AR1_CustomerMaster AR1 ON (ARD.SalesPersonNumber =
    > AR1.SalesPersonCode)}";
    >
    > //DataAdapter Setup
    > OdbcDataAdapter adapter = new OdbcDataAdapter(strSQL, myConn);
    >
    > //DataSet, DataAdapter & Table
    > DataSet objDataSet = new DataSet();
    > adapter.Fill(objDataSet, "dtAR1");
    >
    > //Set up a filter to use the text box value...
    > String Filter = "CustomerNumber = 'ABF'";
    >
    > objDataSet.Tables[0].DefaultView.RowFilter = Filter;
    > objDataSet.Tables["dtAR1"].DefaultView.RowFilter = Filter;
    >
    > //Create DataTable & DataView to feed single text box values on
    > form.....
    > DataTable dtAR1 = objDataSet.Tables["dtAR1"];
    > DataView dv1 = new DataView(dtAR1);
    >
    > TextBox3.Text = dv1[0]["CustomerNumber"];
    >
    > dgAR1.DataSource = objDataSet.Tables["dtAR1"];
    >
    > dgAR1.DataBind();
    >
    > }
    > <CODE>
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    RadekP, Apr 30, 2004
    #2
    1. Advertising

  3. Steve Bishop

    RadekP Guest

    Actually you don't need to DataBind TextBox in this case of course so just

    TextBox3.Text = (string) dv1[0]["CustomerNumber"];

    will do ..

    Radek


    "RadekP" <> wrote in message
    news:...
    > Just cast it to string, your manually generated dataset does not have a
    > schema assigned thus it makes use of general objects for column types

    unless
    > you specify it.
    >
    > TextBox3.Text = (string) dv1[0]["CustomerNumber"];
    > TextBox3.DataBind();
    >
    > Radek
    >
    > "Steve Bishop" <> wrote in message
    > news:uhb$...
    > > I can't believe how hard this has been! I'm sure it's just a matter of
    > > finding the right syntax for C#, but
    > > I can't bind a text box right now.
    > > In testing, I'm just trying one text box for now (TextBox3). Help
    > > appreciated C#. Thanks.
    > >
    > > Compiler Error Message: CS0029: Cannot implicitly convert type 'object'
    > > to 'string'
    > > Source Error:
    > > Line 34: DataView dv1 = new DataView(dtAR1);
    > > Line 35:
    > > Line 36: TextBox3.Text = dv1[0]["CustomerNumber"];
    > > Line 37:
    > > Line 38: dgAR1.DataSource = objDataSet.Tables["dtAR1"];
    > >
    > > <CODE>
    > > public void Page_Load(object sender, System.EventArgs e){
    > >
    > > //Connection Setup
    > >
    > > OdbcConnection myConn = new OdbcConnection("dsn=SOTAMAS90AUTO");
    > >
    > > String strSQL = "SELECT AR1.Division + AR1.CustomerNumber As
    > > KeyField, AR1.Division, AR1.CustomerNumber, AR1.CustomerName,
    > > AR1.ContactCode, AR1.City, AR1.State, AR1.ZipCode, AR1.PhoneNumber,
    > > ARD.Name FROM { oj ARD_SalesPersonMasterfile ARD LEFT OUTER JOIN
    > > AR1_CustomerMaster AR1 ON (ARD.SalesPersonNumber =
    > > AR1.SalesPersonCode)}";
    > >
    > > //DataAdapter Setup
    > > OdbcDataAdapter adapter = new OdbcDataAdapter(strSQL, myConn);
    > >
    > > //DataSet, DataAdapter & Table
    > > DataSet objDataSet = new DataSet();
    > > adapter.Fill(objDataSet, "dtAR1");
    > >
    > > //Set up a filter to use the text box value...
    > > String Filter = "CustomerNumber = 'ABF'";
    > >
    > > objDataSet.Tables[0].DefaultView.RowFilter = Filter;
    > > objDataSet.Tables["dtAR1"].DefaultView.RowFilter = Filter;
    > >
    > > //Create DataTable & DataView to feed single text box values on
    > > form.....
    > > DataTable dtAR1 = objDataSet.Tables["dtAR1"];
    > > DataView dv1 = new DataView(dtAR1);
    > >
    > > TextBox3.Text = dv1[0]["CustomerNumber"];
    > >
    > > dgAR1.DataSource = objDataSet.Tables["dtAR1"];
    > >
    > > dgAR1.DataBind();
    > >
    > > }
    > > <CODE>
    > >
    > >
    > > *** Sent via Developersdex http://www.developersdex.com ***
    > > Don't just participate in USENET...get rewarded for it!

    >
    >
    RadekP, Apr 30, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    1,138
    David Wier
    Aug 5, 2005
  2. mr2_93
    Replies:
    1
    Views:
    3,579
    mr2_93
    Oct 2, 2005
  3. Gnarlodious
    Replies:
    4
    Views:
    17,550
    elizas
    May 5, 2010
  4. Replies:
    0
    Views:
    577
  5. San

    how to bind text box

    San, Jul 2, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    119
    Teemu Keiski
    Jul 3, 2003
Loading...

Share This Page