Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert rows to columns from the dataset 1

Status
Not open for further replies.

taree

Technical User
May 31, 2008
316
US
Code:
I have the below information in my dataset and I am just wondering how i can convert the row 
to column show below as a desired output. please help and as always your help is appreciated

ITMENUM	      VENDORNAME	   VENDORSPRICE

2103.501/00010	L240 	           15000
2103.501/00010	M0154              8900
2103.501/00010	N0063 	           11500



ITMENUM	        L240	M0154   N0063                          

2103.501/00010	15000 	8900    11500
 
I tried that before I post here.I am still getting the same error message;

Code:
Line 363:            ' Dim rows As Object = pivot.[Select]("[ITMENUM]=" + row("ITMENUM").ToString())
Line 364:
Line 365:            Dim rows As Object = (pivot.[Select]("[ITMENUM]=" + row("ITMENUM"))).ToString()
Line 366:
Line 367:            Dim pivotRow As DataRow = pivot.NewRow()
 
syntax... in VB + is mathematical and & is for string concatenation.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
YOu can use the"+" in VB for string contaenation, but you will have to put a .ToString after your item:
row("ITEMNUM").toString + ....
 
so far no luck for me :) same error
Code:
Cannot perform '=' operation on System.String and System.Double. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.EvaluateException: Cannot perform '=' operation on System.String and System.Double.

Source Error: 


Line 361:        For Each row As DataRow In source.Rows
Line 362:
Line 363:            Dim rows As Object = pivot.[Select]("[ITMENUM]=" & row("ITMENUM").ToString())
Line 364:            Dim pivotRow As DataRow = pivot.NewRow()
Line 365:
 
confirm the data type for column ITEMNUM is string for both the source and pivot table.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
I checked both source and pivot table. for the source the datatype is char and pivot table it is string.
 
I fixed the above error message. Itmenum column has "/"
like this: 2021.501/00010. I removed both "." and "/" and the error disapeared. Now I am getting a different error
Code:
Unable to cast object of type 'System.DBNull' to type 'System.Data.DataRow'. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.Data.DataRow'.

Source Error: 


Line 367:
Line 368:            If rows.Length = 1 Then
Line 369:                pivotRow = pivotRow(0)
Line 370:                '  pivot.Rows.Add(pivotRow)
Line 371:            Else
 

Source File: S:\bidAnalysis.aspx.vb    Line: 369
 
taree, it looks like you are dependent on us fixing every error you encounter related to pivoting. the stack trace gives you everything you need to solve the error. if you understand what the code is doing it makes perfect sense why you are getting this error.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Jason, it is my understanding that the array of DataRow objects returned by the Select() method, do contain actual data.They are the actual DataRow objects from the Rows collection that met the filter string.

rows.Length = 1 when there is an existing rows. Please correct me if I am wrong.

Code:
   For Each row As DataRow In source.Rows

            Dim rows As Object = pivot.[Select]("[ITMENUM]=" & (row("ITMENUM").ToString))
            Dim test As String = row("ITMENUM").ToString
            Dim pivotRow As DataRow = pivot.NewRow()

            If rows.Length = 1 Then
                pivotRow = pivotRow(0)

            Else
                pivot.Rows.Add(pivotRow)
            End If

            pivotRow("ITMENUM") = row("ITMENUM")
            pivotRow(row("VENDORNAME")) = row("VENDORSPRICE")

        Next
 
correct, this should be working. are you receiving errors or incorrect results from this?

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
I am still strugling to fix the error message. I just can not see why this is not working. the first time it is going the for loop with out any issue but the second time it gives me this error.how can I validate that the
Code:
Unable to cast object of type 'System.DBNull' to type 'System.Data.DataRow'. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.Data.DataRow'.

Source Error: 


Line 368:
Line 369:            If rows.Length = 1 Then
Line 370:                pivotRow = pivotRow(0)
Line 371:
Line 372:            Else
 
pivotRow is referring to a row. pivotRow(0) refers to the 1st column of that row. what you want is to set the pivotrRow to the first row found in the collection of rows
Code:
If rows.Length = 1 Then
   pivotRow = rows(0)
Else
   pivot.Rows.Add(pivotRow)
End If

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
That did it. I just can not thank you enough for your patient and willingness to help me here. I really appreciate your help and time. You are an awesome guy !!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top