Set a text box value to DataView

S

Steve Bishop

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>
 
S

Scott Mitchell [MVP]

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.

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"];


Have you tried:

TextBox3.Text = dv1[0]["CustomerName"].ToString();

???

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,218
Latest member
JolieDenha

Latest Threads

Top