Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Data Bind a Text Box

Reply
Thread Tools

Data Bind a Text Box

 
 
Steve Bishop
Guest
Posts: n/a
 
      04-30-2004
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!
 
Reply With Quote
 
 
 
 
RadekP
Guest
Posts: n/a
 
      04-30-2004
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" <(E-Mail Removed)> wrote in message
news:uhb$(E-Mail Removed)...
> 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!



 
Reply With Quote
 
 
 
 
RadekP
Guest
Posts: n/a
 
      04-30-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:uhb$(E-Mail Removed)...
> > 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!

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
div box questions; float text around a box, fit box to image size Gnarlodious HTML 4 05-05-2010 11:30 AM
How to bind JTable and data in a text file ? tobleron Java 24 11-10-2008 02:58 PM
confused by boost::bind & boost::lambda::bind XHengDF@gmail.com C++ 0 05-29-2007 04:37 AM
Using a data-bind dropdownlist to populate another data-bind dropdownlist mr2_93 ASP .Net 1 10-02-2005 05:07 PM
how to bind text box San ASP .Net Web Controls 1 07-03-2003 06:31 AM



Advertisments