ASP/Database problem (Long)

SELECT tblCodes.*
FROM tblCodes

WHERE CodeStatus = 'In Progress' OR CodeStatus = 'Initiation'

I've then selected the CodeID column to be used in the DropDownMenu.
 
Another guy gave me this response, unfortunately I don't really know how to work around what he's saying.

Data Type of codeStatus is ManHours.CodeStatusDataTable. Some sort of Data Table. You cant convert a datatable into a valid string using ToString() function.

So when you are using tostring the .net compiler is just returning the name of the Variable. That is the reason why the textbox is always displaying codeStatus.

Simply put, whenever ToString() encounters a invalid input it usually returns some general string like name of the control or base class name.. it wont generate an error. So you need to work around this.
 
Just had a look at your code again.

Basically what he is saying is you have created a datatable and filled it using your query.
Code:
codeStatus = codestatusAdapter.GetCodeStatus(CodeID)

Because a datatable is structured like a table it contains columns and rows containing your values. So when you use the following code it is just bringing back a generic string.
Code:
TimeCodeStatusTextBox.Text = codeStatus.ToString()

What you need to do is get the value you want from a row in the datatable.
Firstly where you created your data table and data adapter variables create a new one for a data row.
Code:
Dim codestatusRow As ManHours.CodeStatusDataRow

Assign the row to the row in your data table.
Code:
codestatusRow = codeStatus.Rows(0)

Then assign your textbox to the column in that row to get your value.
Code:
TimeCodeStatusTextBox.Text = codestatusRow.Field Name In Your Table
 
Last edited:
Ok I understand that, but not well enough to diagnose the problem. Here's the code and i've highlighted the problems.

Code:
    Protected Sub TimeCodeDropDown_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim CodeID As New Integer
        Dim TimeCodeDropDown As New DropDownList
        Dim TimeCodeStatusTextBox As New TextBox

        Dim codestatusAdapter As New ManHoursTableAdapters.CodeStatusTableAdapter()
        Dim codeStatus As ManHours.CodeStatusDataTable
        Dim codeStatusRow As ManHours.CodeStatusRow()

        TimeCodeDropDown = CType(DetailsView1.FindControl("TimeCodeDropDown"), DropDownList)
        TimeCodeStatusTextBox = CType(DetailsView1.FindControl("TimeCodeStatus"), TextBox)


        CodeID = TimeCodeDropDown.SelectedValue

        codeStatus = codestatusAdapter.GetCodeStatus(CodeID)

        codeStatusRow = [B]codeStatus.Rows(0)[/B] [COLOR="Red"][B] // Value of type 'System.Data.DataRow' cannot be converted to '1-dimensional array' of ManHours.CodeStatusRow.[/B][/COLOR]

        TimeCodeStatusTextBox.Text = [B]codeStatusRow.CodeID[/B] [B][COLOR="red"]// 'CodeID' is not a member of 'Systems.Array'.[/COLOR][/B]


    End Sub
 
Thought this might happen, can't remember the correct syntax to use. :rolleyes::o:D

First try changing the codestatusRow part to the following and try it again:
Code:
codestatusRow = codeStatus(0)

If that doesn't work then change to the following:
Code:
Dim codestatusRow As DataRow
Code:
codestatusRow = codeStatus.Rows(0)
Code:
TimeCodeStatusTextBox.Text = codeStatusRow("CodeID").ToString
 
Type 'DataRow' is not defined.

Code:
  Dim CodeID As New Integer
        Dim TimeCodeDropDown As New DropDownList
        Dim TimeCodeStatusTextBox As New TextBox

        Dim codestatusAdapter As New ManHoursTableAdapters.CodeStatusTableAdapter()
        Dim codeStatus As ManHours.CodeStatusDataTable
        Dim codeStatusRow As ManHours.CodeStatusRow()

        TimeCodeDropDown = CType(DetailsView1.FindControl("TimeCodeDropDown"), DropDownList)
        TimeCodeStatusTextBox = CType(DetailsView1.FindControl("TimeCodeStatus"), TextBox)


        CodeID = TimeCodeDropDown.SelectedValue

        codeStatus = codestatusAdapter.GetCodeStatus(CodeID)

        codeStatusRow = [B]codeStatus(0)[/B] [B][COLOR="Red"]// Value of type 'System.Data.DataRow' cannot be converted to '1-dimensional array' of ManHours.CodeStatusRow.[/COLOR][/B]
        TimeCodeStatusTextBox.Text = codeStatusRow("CodeID").ToString

Still get that error even if I use codeStatusRow = codeStatus(0).

I've been posting in the thread below about the problem and a reply i've just got has me abit lost, maybe it gives you a better idea? Thanks for all this you've been a massive help, I really don't have anyone else to ask :)

http://forums.asp.net/p/1183874/2042825.aspx
 
Have you tried the other method I posted.

Change:
Code:
Dim codeStatusRow As ManHours.CodeStatusRow()
To:
Code:
Dim codeStatusRow As New DataRow

Change:
Code:
codeStatusRow = codeStatus(0)
To:
Code:
codeStatusRow = codeStatus.Rows(0)
 
I've just created a test page and this is what works for me, I've replaced some bits to match your code:

Code:
Dim codestatusAdapter As New ManHoursTableAdapters.CodeStatusTableAdapter()
Dim codeStatus As ManHours.CodeStatusDataTable
Dim codeStatusRow As DataRow
Dim CodeID As Integer
Dim TimeCodeStatusTextBox As New TextBox

' I have created a variable above for your CodeID value below, I am guessing it is an integer
CodeID = TimeCodeDropDown.SelectedValue
TimeCodeStatusTextBox = CType(DetailsView1.FindControl("TimeCodeStatus"), TextBox)
codeStatus = codestatusAdapter.GetCodeStatus(CodeID)

codeStatusRow = codeStatus.Rows(0)
TimeCodeStatusTextBox.Text = codeStatusRow("CodeID").ToString

Also make sure you have another import at the top for the DataRow.

Code:
Imports System.Data

HTH
 
How did you get that to work when the TimeCodeDropDown is in a DetailsView. I tried messing around with CType but i'm not sure how you can use that and get the SelectedValue?
 
I just used it as an example, so add in the required bits from the code you posted.
But your saying that you tried that code and it didn't work?
What happens when you debug it?
 
If I use:

CodeID = CType(DetailsView1.FindControl("TimeCodeDropDown.SelectedValue"), DropDownList

I get an error saying "Value of type 'System.Web.UI.WebControls.DropDownList" cannon be converted to Integer.
 
CodeID = CType(DetailsView1.FindControl("TimeCodeDropDown.S electedValue").ToString(), DropDownList

try that

Stelly
 
Is that doesnt work, try this....

dropdownlist TCDdl = DetailsView1.FindControl("TimeCodeDropDown")

codeID = Convert.ToInt32(TCDdl.Selectedvalue.ToString())

Let me know if it works

Stelly
 
This is from one of your posts add it in your existing code somewhere:
Code:
TimeCodeDropDown = CType(DetailsView1.FindControl("TimeCodeDropDown"), DropDownList)

CodeID = Convert.ToInt32(TimeCodeDropDown.SelectedValue)

If that doesn't work try changing 'Convert.ToInt32' to 'CInt'.

EDIT: You might need to put .ToString() on the end of SelectedValue as well.
 
Last edited:
This is from one of your posts add it in your existing code somewhere:
Code:
TimeCodeDropDown = CType(DetailsView1.FindControl("TimeCodeDropDown"), DropDownList)

CodeID = Convert.ToInt32(TimeCodeDropDown.SelectedValue)

If that doesn't work try changing 'Convert.ToInt32' to 'CInt'.

EDIT: You might need to put .ToString() on the end of SelectedValue as well.

I dont think that he will have too

Stelly
 
Code:
 Dim codestatusAdapter As New ManHoursTableAdapters.CodeStatusTableAdapter()
        Dim codeStatus As ManHours.CodeStatusDataTable
        Dim codeStatusRow As DataRow
        Dim CodeID As Integer
        Dim TimeCodeStatusTextBox As New TextBox
        Dim TimeCodeDropDown As New DropDownList

        TimeCodeDropDown = CType(DetailsView1.FindControl("TimeCodeDropDown"), DropDownList)

        CodeID = Convert.ToInt32(TimeCodeDropDown.SelectedValue)


        TimeCodeStatusTextBox = CType(DetailsView1.FindControl("TimeCodeStatus"), TextBox)
        codeStatus = codestatusAdapter.GetCodeStatus(CodeID)

        codeStatusRow = codeStatus.Rows(0)
        [B]TimeCodeStatusTextBox.Text = codeStatusRow("CodeID").ToString[/B]

When I select a code from my DropDownMenu I get the following error on the line in bold:

Column 'CodeID' does not belong to the table CodeStatus
 
Back
Top Bottom