Value of type 'System.Data.Dataset' cannot be converted to 'String'

I receive the above error for line 57 which is:

 Address.text = Clientinfo(DropDownlist1.Items(DropDownList1.SelectedIndex).text) 

I'm trying to take the selected item from the dropdownlist1 and have the data from the query 'Clientinfo' appear using the label control called 'address'. I plan to format it to be used as a mailing address:
123 Street
City, State Zip
Etc.
Obviously I am learning as I go. Can anyone give me an alternative or find my error. Much appreciated. The code is below:

Sub Page_Load(Sender As Object, E As EventArgs)
If Not Page.IsPostBack Then
DropDownList1.DataTextField = "ClientsFullName"
DropDownList1.DataSource = ClientDropDown()
DropDownlist1.Databind()
End If
End Sub
Function ClientDropDown() As System.Data.DataSet
Dim connectionString As String = "server='(local)'; trusted_connection=true; database='porman'"
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT [Clients].[ClientsFullName] FROM [Clients]"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Function
Function Clientinfo(ByVal clientsFullName As String) As System.Data.DataSet
Dim connectionString As String = "server='(local)'; trusted_connection=true; database='porman'"
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT [Clients].[ClientsFullName], [Clients].[ClientsStreet], [Clients].[Clients"& _
"City], [Clients].[ClientsState], [Clients].[ClientsZip], [Clients].[ClientsPhone"& _
"], [Clients].[ClientsEmail], [Clients].[ClientsPhone2] FROM [Clients] WHERE ([Cl"& _
"ients].[ClientsFullName] = @ClientsFullName)"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_clientsFullName As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_clientsFullName.ParameterName = "@ClientsFullName"
dbParam_clientsFullName.Value = clientsFullName
dbParam_clientsFullName.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_clientsFullName)
Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Function
Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
Address.text = Clientinfo(DropDownlist1.Items(DropDownList1.SelectedIndex).text)
Address.databind()
End Sub

0
R
8/21/2003 5:19:42 PM
asp.net.object-datasource 16182 articles. 0 followers. Follow

2 Replies
4129 Views

Similar Articles

[PageSpeed] 42
Get it on Google Play
Get it on Apple App Store

The function ClientInfo(..) returns a DataSet and you are trying to assign a dataset to Address.text 

In cas you want to assign any value to the address.Text (where you can assign string)
try giving

Address.text = Clientinfo(DropDownlist1.Items(DropDownList1.SelectedIndex).text).Tables(0).Rows(0)(0).ToString()

Index is given for first row first column
change it according to your requirement
you dont need to give
Address.Databind in case its a label control

Sushila Bowalekar Patel
Visual ASP/ASP.NET MVP
http://weblogs.asp.net/sushilasb
0
SushilaSB
8/21/2003 6:13:58 PM
Can't assign dataset object directly to label's text property.  Try to extract each field value from the dataset and create the desired string from them.

Try something like this:
Dim objDS As DataSet = Clientinfo(DropDownlist1.Items(DropDownList1.SelectedIndex).text)
Dim strFullAddr As String = objDS.Tables(0).Rows(0).Item("ClientsStreet") & " " & _
objDS.Tables(0).Rows(0).Item("ClientsCity") & ......
Address.Text = strFullAddr
0
leecs1
8/21/2003 6:20:49 PM
Reply:

Similar Artilces:

convert type 'System.Data.DataSet' to 'System.Data.DataTable'
 I got this error  : Cannot implicitly convert type 'System.Data.DataSet' to 'System.Data.DataTable' i have written code like thisDataTable dt = new DataTable(); dt = GetGalleryImages(name); Possibly coz GetGalleryImages returns a dataset and not a datatable? Try: DataSet ds = GetGalleryImages(name); what type does GetGalleryImages return?  If this returns a dataset then you will have to change datatable to dataset, then index the table of the dataset.Please mark as answer if you find helpful.Ustes G....

Null values and Profile data "Unable to cast object of type 'System.DBNull' to type 'System.String'"
I've made my own ProfileProvider but when I am trying to read null values by txt.Text = Profile.FirstName I get the error "Unable to cast object of type 'System.DBNull' to type 'System.String'."This is how the code (which I don't write by myself looks like): How to fix the problem??public virtual string FirstName { get { return ((string)(this.GetPropertyValue("FirstName"))); } set { this.SetPropertyValue("FirstName", value); } }  You can check for a null value as sh...

Update error , "Unable to cast object of type 'System.DBNull' to type 'System.String'" , using DataSet as a datasource
Hi All, The following sample code is for testing dw.UpdateData using dataset as the data source. The data retrieval and display part under Form1_Load works fine. However, inputting some values in a new row and calling dw.UpdateData causes the following error: "Unable to cast object of type 'System.DBNull' to type 'System.String'" The error seems to occur when a datawindow column value has been changed from null value. Does anyone know how to fix the error ? Thank you for your advice. I use DW2.5 (build 8542), VS2005 pro, MS SQL Express. ...

Value of type 'String' cannot be converted to 'System.Net.Mail.MailAddress'
My code is below:Protected Sub btnSendMsg_OnClick(ByVal Source As Object, ByVal E As EventArgs) Dim myMessage As New System.Net.Mail.MailMessage Dim myAttachment As System.Net.Mail.Attachment Dim myMail As System.Net.Mail.SmtpClient If Page.IsValid() Then myMessage.From = txtFromEmail.Text myMessage.To = txtToEmail.TextWhat can I do to fix this? MailMessage.To represents a collection that you Add addresses to.Dim recipient As MailAddress= new MailAddress(txtToEmail.Text) myMessage.To.Add(recipient)    Mike Banavige~~~~~~~~~~...

Error : Value of type 'System.Data.DataTable' cannot be converted to 'String'
Hi, I have a compilation error : Value of type 'System.Data.DataTable' cannot be converted to 'String'. I want to erase all the records in my Access database and update it with a DataTable. My code lines : Dim conn As OleDbConnection Dim da As OleDbDataAdapter Dim ds As DataSet Dim sql As String sql = "SELECT * FROM menu;" conn = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=d:\www\tgc\prof_tech\fsthilaire\parametres_site\parametres_site.mdb" ) da = New OleDbDataAdapter(sql, conn) conn.Open() ds = New DataS...

Cannot implicitly convert type 'System.Data.DataTable' to 'System.Data.Dataset'
I am using an excel spreadsheet as a data source to build a dataset which is then used to populate a grid:  I am getting the following error: Cannot implicitly convert type 'System.Data.DataTable' to 'System.Data.Dataset' Here's my code:private DataSet GetData(String description, String mpnumber, String link) { //MPData will represents the Data in Application Cache. We will use Cache Data //for performance purposes, because MP Information will not change often. I choose // to also use Dataset Filtering instead of SQL Server Filtering. However the DataAccess l...

Object of type 'System.DBNull' cannot be converted to type 'System.String' from formview
I have a formview that I am using for input to my datatable.  I am using an objectdatasource that uses a BLL.  This in turn points to my XSD tableadapter. When I test, and only fill in the required fields, I am getting the error Object of type 'System.DBNull' cannot be converted to type 'System.String' I am not sure what field is having the issue.  In my BLL for the Add, I have checked the dates for null and placed the value of DateTime.MinValue.  For the text fields, I have place "" if they are null.  Is this error being create prior to...

Cast from type ''''DBNull'''' to type ''''String'''' is not valid.
How do I avoid getting this error: Cast from type ''''DBNull'''' to type ''''String'''' is not valid. I am trying to get values from the database into a form for updating using a Datareader, SQL is set to allow nulls for certain fields as they are not required but the only way I can get the form to display is by adding a space in SQL. Is there another way around this? Check if it is equal to DBNull.Value first and if it is, don't do the cast.Stanley Tan theSpoke Blog Where in the code does it need to go? I am using the following and it's the profile that isn't always requi...

Unable to cast object of type 'System.String' to type 'System.Data.DataRowView'
Hi, I am having this problem: Unable to cast object of type 'System.String' to type 'System.Data.DataRowView'I have two repeaters: One is for a list of terms and the other show the definition. What I am trying to do is, highlight the selected term.Here is the relevant code which has this error:private Color SetButtonBackColor(object dataItem){ Response.Write("<br />In SetButtonBackColor Function"); Response.Write("<br>dataItem in SetColor is: " +(string)((DataRowView)dataItem)["TermIndex"]); string _initial =  (string) ((DataRowView)dataItem)["TermIndex"]; &n...

BC30311: Value of type 'System.Data.SqlClient.SqlDataReader' cannot be converted to 'String'.
Does anyone know what the problem is? Sub Page_Init(sender As Object, e As EventArgs) Dim txtName As New TextBox() Dim txtPart As New TextBox() Dim txtEach As New TextBox() Dim txtTotal1 As New TextBox() Dim txtSubtotal As New TextBox() Dim txtTax As New TextBox() Dim txtShipping As New TextBox() Dim txtTotal2 As New TextBox() Dim prod_id As Integer Dim id As Integer id = Request.Querystring("prod_id") txtName.Text = GetName(id).................this is the problem line phName.C...

BC30311: Value of type 'System.Data.SqlClient.SqlDataReader' cannot be converted to 'String'.
Hello, I am developing a page and when I try to call the function GetName(id) to populate the textbox I get the error. Can anyone explain why I am getting this error? Thank you in advance. Sub Page_Load(sender As Object, e As EventArgs) Dim prod_id As Integer Dim id As Integer id = Request.QueryString("prod_id") Response.Write(id) Dim txtName As New TextBox() txtName.Text = GetName(id) Dim txtPart As New TextBox() Dim txtEach As New TextBox() Dim txtTotal1 As New TextBox() Dim txtSubtotal As New T...

Cannot convert value of parameter 'Course_FK' from 'System.String' to 'System.Guid'
Hi, I'm building a site and I've been trying to accomplish something similar to what is talked about in "Working with Data in ASP.NET 2.0 :: Declarative Parameters" tutorial. Below is the code for my methods from the xsd. I tried to attach a screenshot of my xsd but for some reason I'm not allowed GetAllCourseNames() SELECT        CourseID, NameFROM            Course GetCourseScheduleByCourseID SELECT        ScheduleID, Course_FK, Date, TeeTime, NumberOfPlayersF...

Value of type 'System.Net.Mail.MailMessage' cannot be converted to 'System.Net.Mail.AlternateView'
Trying to create an alternateview to send a txt email with the html formatted email.  I've used string builder to create the whole email, but I get this error.  Any ideas why?  i've bolded the line that throws the error... Dim EmailBodyTxt As New StringBuilder EmailBodyTxt.Append("<html><style type='text/css'>.table{border:solid; border-color:#006666; width:600;} ")EmailBodyTxt.Append("<body><table class='table'><tr><td colspan='2'><h1>Test<br />RESPONSE SYSTEM</h1></td>...

convert type 'System.Xml.XmlDataDocument' to 'System.Data.DataSet'
I am using XMLDataDocument in web services which returns XMLDataDocument using this XMLDataDocument for Dataset in application getting error Cannot implicitly convert type 'System.Xml.XmlDataDocument' to 'System.Data.DataSet'  any idea  XmlDataDocument has DataSet property to get the document as a data set.Thanks,Teemu KeiskiFinland, EU  [WebMethod]    public XMLDataDocument xmldoc(DateTime x, DateTime y)    {        df = dateFrom;        dt = dateTo;   &...

Web resources about - Value of type 'System.Data.Dataset' cannot be converted to 'String' - asp.net.object-datasource

Resources last updated: 1/7/2016 3:42:41 PM