473,398 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Data Bind a Text Box

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
2 6754
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Steve Bishop | last post by:
All the examples I have bind text boxes to the DataReader. Can someone give me an example on how to bind some text boxes or labels to my DataSet object. Help appreciated. Thanks. Steve ...
0
by: Pavils Jurjans | last post by:
Hello, I have a third-paty application that uses text type field in MSSQL server to store data of incoming emails (full raw sources, including headers, etc.). Since the emails come in different...
3
by: John Crowley | last post by:
I've run into a problem where drop down lists are refusing to data bind with the following error on the DataBind() call Specified argument was out of the range of valid values. Parameter name:...
1
by: mr2_93 | last post by:
Hi All, I am new to ASP.NET and I am looking for help with the dropdownlist data control. I wonder if someone could show me how to past the SelectedValue of a data-bind dropdownlist to...
2
by: Henry Lee | last post by:
hi, In ASP 2.0 , using datasource object with Gridview databind feature is really easy to show records from database. However , I want to do the samething but using textbox object because there...
7
by: Ryan Liu | last post by:
Hi, I want to backup database to a text file. There are binary columns. I read byte from the column and use ASCII encoding convert it to string and write to a text file. But there are bytes...
2
by: si_owen | last post by:
Hi all, firstly this is a web apps project. Right i had a dropdown list which was populated by a db table which was databound using a sql datasource. however when adding validation controls...
3
by: gujarsachin2001 | last post by:
Hi friends, I m just stuck with extracting excel file data into text file. So can any body please help me out. thx, Sachin.
2
by: =?Utf-8?B?Tmc=?= | last post by:
Hi. have someone can give me some idea how to start. the thing i want do is using web page export the sql data to text file then let user download. eg. the webpage has one button. when user...
0
by: betchay1219 | last post by:
How can I data bind radio buttons or option button using VB.Net , window application
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.