By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,984 Members | 2,794 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,984 IT Pros & Developers. It's quick & easy.

Data Bind a Text Box

P: n/a
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!
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <st****@viper.com> wrote in message
news:uh**************@tk2msftngp13.phx.gbl...
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!

Nov 18 '05 #2

P: n/a
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" <ra***@aldec.com> wrote in message
news:Ou*************@TK2MSFTNGP11.phx.gbl...
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" <st****@viper.com> wrote in message
news:uh**************@tk2msftngp13.phx.gbl...
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!


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.