Unable to sort Dataview

A

Amritha.Datta

Hi, I was trying to sort dataview using the below process. It is
throwing exception. Please help.


Dim DSExcel1 As DataSet
DSExcel1 = New DataSet

Dim myView As DataView
myView = DSExcel.Tables(0).DefaultView

myView.Sort = "Column_One"


DSExcel is a dataset with one table and 8 columns.

NOTE: "Column_One" is DSExcel.Tables(0).Columns(0).ColumnName


In the exception it says : Message "Cannot find column Column_One."
String


Thanks.
 
M

Miha Markic [MVP C#]

I guess the table you are assuming to be at position 0 is not there.
Why don't you try to look into its columns in debugger?
How do you load the table?
 
A

Amritha.Datta

Hi Miha Markic, Thanks for your response. Here is the code that loads
the table.

Dim DSExcel As DataSet
Dim strSelect As String
strSelect = "Select from [" & strSheetName & "$]"
Dim objCmd As New OleDb.OleDbCommand(strSelect, Conn)

Dim daExcel As New OleDb.OleDbDataAdapter

DSExcel = New DataSet

daExcel.SelectCommand = objCmd
daExcel.Fill(DSExcel)

Dim DSExcel1 As DataSet
DSExcel1 = New DataSet

Dim myView As New DataView
myView = DSExcel.Tables(0).DefaultView

myView.Sort = "COLUMN_ONE "

NOTE: I debugged and checked the values of
DSExcel.Tables(0).Columns(0).ColumnName,
myView.Tables(0).Columns(0).ColumnName . both are "COLUMN_ONE "
In fact "COLUMN_ONE " is the name of first column in the spreadsheed
that I was uploading. In the quickwatch I saw there is a space
character at the end "COLUMN_ONE "


Please advise.

Thanks,

I guess the table you are assuming to be at position 0 is not there.
Why don't you try to look into its columns in debugger?
How do you load the table?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & developmentwww.rthand.com
Blog:http://cs.rthand.com/blogs/blog_with_righthand/


Hi, I was trying tosortdataviewusing the below process. It is
throwing exception. Please help.
Dim DSExcel1 As DataSet
DSExcel1 = New DataSet
Dim myView AsDataView
myView = DSExcel.Tables(0).DefaultView
myView.Sort= "Column_One"
DSExcel is a dataset with one table and 8 columns.
NOTE: "Column_One" is DSExcel.Tables(0).Columns(0).ColumnName
In the exception it says : Message "Cannot find columnColumn_One."
String
 
M

Miha Markic [MVP C#]

Try putting column name into square brackets, like myView.Sort =
"[COLUMN_ONE ]"

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Hi Miha Markic, Thanks for your response. Here is the code that loads
the table.

Dim DSExcel As DataSet
Dim strSelect As String
strSelect = "Select from [" & strSheetName & "$]"
Dim objCmd As New OleDb.OleDbCommand(strSelect, Conn)

Dim daExcel As New OleDb.OleDbDataAdapter

DSExcel = New DataSet

daExcel.SelectCommand = objCmd
daExcel.Fill(DSExcel)

Dim DSExcel1 As DataSet
DSExcel1 = New DataSet

Dim myView As New DataView
myView = DSExcel.Tables(0).DefaultView

myView.Sort = "COLUMN_ONE "

NOTE: I debugged and checked the values of
DSExcel.Tables(0).Columns(0).ColumnName,
myView.Tables(0).Columns(0).ColumnName . both are "COLUMN_ONE "
In fact "COLUMN_ONE " is the name of first column in the spreadsheed
that I was uploading. In the quickwatch I saw there is a space
character at the end "COLUMN_ONE "


Please advise.

Thanks,

I guess the table you are assuming to be at position 0 is not there.
Why don't you try to look into its columns in debugger?
How do you load the table?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & developmentwww.rthand.com
Blog:http://cs.rthand.com/blogs/blog_with_righthand/


Hi, I was trying tosortdataviewusing the below process. It is
throwing exception. Please help.
Dim DSExcel1 As DataSet
DSExcel1 = New DataSet
Dim myView AsDataView
myView = DSExcel.Tables(0).DefaultView
myView.Sort= "Column_One"
DSExcel is a dataset with one table and 8 columns.
NOTE: "Column_One" is DSExcel.Tables(0).Columns(0).ColumnName
In the exception it says : Message "Cannot find columnColumn_One."
String
 
A

Amritha.Datta

It returns the same error. Is there anything to do with
GetOleDbSchemaTable ?

Pls advise.

Thanks.

Try putting column name into square brackets, like myView.Sort =
"[COLUMN_ONE ]"

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & developmentwww.rthand.com
Blog:http://cs.rthand.com/blogs/blog_with_righthand/


Hi Miha Markic, Thanks for your response. Here is the code that loads
the table.
Dim DSExcel As DataSet
Dim strSelect As String
strSelect = "Select from [" & strSheetName & "$]"
Dim objCmd As New OleDb.OleDbCommand(strSelect, Conn)
Dim daExcel As New OleDb.OleDbDataAdapter
DSExcel = New DataSet
daExcel.SelectCommand = objCmd
daExcel.Fill(DSExcel)
Dim DSExcel1 As DataSet
DSExcel1 = New DataSet
Dim myView As New DataView
myView = DSExcel.Tables(0).DefaultView
myView.Sort = "COLUMN_ONE "
NOTE: I debugged and checked the values of
DSExcel.Tables(0).Columns(0).ColumnName,
myView.Tables(0).Columns(0).ColumnName . both are "COLUMN_ONE "
In fact "COLUMN_ONE " is the name of first column in the spreadsheed
that I was uploading. In the quickwatch I saw there is a space
character at the end "COLUMN_ONE "
Please advise.

I guess the table you are assuming to be at position 0 is not there.
Why don't you try to look into its columns in debugger?
How do you load the table?
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & developmentwww.rthand.com
Blog:http://cs.rthand.com/blogs/blog_with_righthand/

Hi, I was trying tosortdataviewusing the below process. It is
throwing exception. Please help.
Dim DSExcel1 As DataSet
DSExcel1 = New DataSet
Dim myView AsDataView
myView = DSExcel.Tables(0).DefaultView
myView.Sort= "Column_One"
DSExcel is a dataset with one table and 8 columns.
NOTE: "Column_One" is DSExcel.Tables(0).Columns(0).ColumnName
In the exception it says : Message "Cannot find columnColumn_One."
String
Thanks.
 
M

Miha Markic [MVP C#]

Use DataSet.WriteXml method to create a file of serialized dataset and send
it to me (or attach it to your reply).

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

It returns the same error. Is there anything to do with
GetOleDbSchemaTable ?

Pls advise.

Thanks.

Try putting column name into square brackets, like myView.Sort =
"[COLUMN_ONE ]"

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & developmentwww.rthand.com
Blog:http://cs.rthand.com/blogs/blog_with_righthand/


Hi Miha Markic, Thanks for your response. Here is the code that loads
the table.
Dim DSExcel As DataSet
Dim strSelect As String
strSelect = "Select from [" & strSheetName & "$]"
Dim objCmd As New OleDb.OleDbCommand(strSelect, Conn)
Dim daExcel As New OleDb.OleDbDataAdapter
DSExcel = New DataSet
daExcel.SelectCommand = objCmd
daExcel.Fill(DSExcel)
Dim DSExcel1 As DataSet
DSExcel1 = New DataSet
Dim myView As New DataView
myView = DSExcel.Tables(0).DefaultView
myView.Sort = "COLUMN_ONE "
NOTE: I debugged and checked the values of
DSExcel.Tables(0).Columns(0).ColumnName,
myView.Tables(0).Columns(0).ColumnName . both are "COLUMN_ONE "
In fact "COLUMN_ONE " is the name of first column in the spreadsheed
that I was uploading. In the quickwatch I saw there is a space
character at the end "COLUMN_ONE "
Please advise.

On Mar 26, 10:14 am, "Miha Markic [MVP C#]" <miha at rthand com>
wrote:
I guess the table you are assuming to be at position 0 is not there.
Why don't you try to look into its columns in debugger?
How do you load the table?
Hi, I was trying tosortdataviewusing the below process. It is
throwing exception. Please help.
Dim DSExcel1 As DataSet
DSExcel1 = New DataSet
Dim myView AsDataView
myView = DSExcel.Tables(0).DefaultView
myView.Sort= "Column_One"
DSExcel is a dataset with one table and 8 columns.
NOTE: "Column_One" is DSExcel.Tables(0).Columns(0).ColumnName
In the exception it says : Message "Cannot find columnColumn_One."
String
 
A

Amritha.Datta

Hi I am not able to attach the file. SO I am pasting the XML data
here.

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Table>
<COLUMN_ONE_x00A0_>R01AH0030D </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>O65LKDIAM </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDLKSIAMO65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AH1101 </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>U65LKDIAM </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>PPOLKDIAMU65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0269 </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>U65NR </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>PPONRU65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0069 </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>U65NR </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>THPNRU65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0019D </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>O65LKD </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDLKDMSPO65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0011D </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>O65NR </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDNRO65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0075D </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>O65NR </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDNRO65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0076D </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>O65NR </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDNRO65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0011 </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>U65NR </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDNRU65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01BH0030D </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>O65LKDIAM </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDLKSIAMO65 </COLUMN_FOUR_x00A0_>
</Table>
</NewDataSet>

I don't have any idea why it is appending _x00A0_ .

Thanks

Use DataSet.WriteXml method to create a file of serialized dataset and send
it to me (or attach it to your reply).

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & developmentwww.rthand.com
Blog:http://cs.rthand.com/blogs/blog_with_righthand/


It returns the same error. Is there anything to do with
GetOleDbSchemaTable ?
Pls advise.

Try putting column name into square brackets, like myView.Sort =
"[COLUMN_ONE ]"
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & developmentwww.rthand.com
Blog:http://cs.rthand.com/blogs/blog_with_righthand/

Hi Miha Markic, Thanks for your response. Here is the code that loads
the table.
Dim DSExcel As DataSet
Dim strSelect As String
strSelect = "Select from [" & strSheetName & "$]"
Dim objCmd As New OleDb.OleDbCommand(strSelect, Conn)
Dim daExcel As New OleDb.OleDbDataAdapter
DSExcel = New DataSet
daExcel.SelectCommand = objCmd
daExcel.Fill(DSExcel)
Dim DSExcel1 As DataSet
DSExcel1 = New DataSet
Dim myView As New DataView
myView = DSExcel.Tables(0).DefaultView
myView.Sort = "COLUMN_ONE "
NOTE: I debugged and checked the values of
DSExcel.Tables(0).Columns(0).ColumnName,
myView.Tables(0).Columns(0).ColumnName . both are "COLUMN_ONE "
In fact "COLUMN_ONE " is the name of first column in the spreadsheed
that I was uploading. In the quickwatch I saw there is a space
character at the end "COLUMN_ONE "
Please advise.
Thanks,
On Mar 26, 10:14 am, "Miha Markic [MVP C#]" <miha at rthand com>
wrote:
I guess the table you are assuming to be at position 0 is not there.
Why don't you try to look into its columns in debugger?
How do you load the table?
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & developmentwww.rthand.com
Blog:http://cs.rthand.com/blogs/blog_with_righthand/

Hi, I was trying tosortdataviewusing the below process. It is
throwing exception. Please help.
Dim DSExcel1 As DataSet
DSExcel1 = New DataSet
Dim myView AsDataView
myView = DSExcel.Tables(0).DefaultView
myView.Sort= "Column_One"
DSExcel is a dataset with one table and 8 columns.
NOTE: "Column_One" is DSExcel.Tables(0).Columns(0).ColumnName
In the exception it says : Message "Cannot find columnColumn_One."
String
Thanks.
 
M

Miha Markic [MVP C#]

It doesn't work because the last char isn't a space. Instead of 32 it has a
value of 160.
Thus, something like this will work:
view.Sort = "[" + ds.Tables[0].Columns[0].ColumnName + "]"

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Hi I am not able to attach the file. SO I am pasting the XML data
here.

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Table>
<COLUMN_ONE_x00A0_>R01AH0030D </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>O65LKDIAM </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDLKSIAMO65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AH1101 </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>U65LKDIAM </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>PPOLKDIAMU65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0269 </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>U65NR </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>PPONRU65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0069 </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>U65NR </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>THPNRU65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0019D </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>O65LKD </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDLKDMSPO65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0011D </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>O65NR </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDNRO65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0075D </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>O65NR </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDNRO65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0076D </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>O65NR </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDNRO65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0011 </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>U65NR </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDNRU65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01BH0030D </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>O65LKDIAM </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDLKSIAMO65 </COLUMN_FOUR_x00A0_>
</Table>
</NewDataSet>

I don't have any idea why it is appending _x00A0_ .

Thanks

Use DataSet.WriteXml method to create a file of serialized dataset and
send
it to me (or attach it to your reply).

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & developmentwww.rthand.com
Blog:http://cs.rthand.com/blogs/blog_with_righthand/


It returns the same error. Is there anything to do with
GetOleDbSchemaTable ?
Pls advise.

On Mar 26, 11:34 am, "Miha Markic [MVP C#]" <miha at rthand com>
wrote:
Try putting column name into square brackets, like myView.Sort =
"[COLUMN_ONE ]"
Hi Miha Markic, Thanks for your response. Here is the code that
loads
the table.
Dim DSExcel As DataSet
Dim strSelect As String
strSelect = "Select from [" & strSheetName & "$]"
Dim objCmd As New OleDb.OleDbCommand(strSelect, Conn)
Dim daExcel As New OleDb.OleDbDataAdapter
DSExcel = New DataSet
daExcel.SelectCommand = objCmd
daExcel.Fill(DSExcel)
Dim DSExcel1 As DataSet
DSExcel1 = New DataSet
Dim myView As New DataView
myView = DSExcel.Tables(0).DefaultView
myView.Sort = "COLUMN_ONE "
NOTE: I debugged and checked the values of
DSExcel.Tables(0).Columns(0).ColumnName,
myView.Tables(0).Columns(0).ColumnName . both are "COLUMN_ONE "
In fact "COLUMN_ONE " is the name of first column in the spreadsheed
that I was uploading. In the quickwatch I saw there is a space
character at the end "COLUMN_ONE "
Please advise.

On Mar 26, 10:14 am, "Miha Markic [MVP C#]" <miha at rthand com>
wrote:
I guess the table you are assuming to be at position 0 is not
there.
Why don't you try to look into its columns in debugger?
How do you load the table?
Hi, I was trying tosortdataviewusing the below process. It is
throwing exception. Please help.
Dim DSExcel1 As DataSet
DSExcel1 = New DataSet
Dim myView AsDataView
myView = DSExcel.Tables(0).DefaultView
myView.Sort= "Column_One"
DSExcel is a dataset with one table and 8 columns.
NOTE: "Column_One" is DSExcel.Tables(0).Columns(0).ColumnName
In the exception it says : Message "Cannot find
columnColumn_One."
String
 
C

Cor Ligthert [MVP]

Hi,

Can you try this one

Dim DSExcel As DataSet
Dim strSelect As String = "Select from [" & strSheetName &
"$]"
Dim daExcel As New OleDb.OleDbDataAdapter(strSelect, Conn)
daExcel.Fill(DSExcel)
Dim myView As New DataView(DSExcel)
myView.Sort = dsExcel.Tables(0).Column(0).ColumnName

I tried to show you how to make it a little bit shorter as well, but did all
typing in this message so watch typos.

Cor
 
C

Cor Ligthert [MVP]

C# code in VB.Net?

:)

Cor

Miha Markic said:
Try putting column name into square brackets, like myView.Sort =
"[COLUMN_ONE ]"

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Hi Miha Markic, Thanks for your response. Here is the code that loads
the table.

Dim DSExcel As DataSet
Dim strSelect As String
strSelect = "Select from [" & strSheetName & "$]"
Dim objCmd As New OleDb.OleDbCommand(strSelect, Conn)

Dim daExcel As New OleDb.OleDbDataAdapter

DSExcel = New DataSet

daExcel.SelectCommand = objCmd
daExcel.Fill(DSExcel)

Dim DSExcel1 As DataSet
DSExcel1 = New DataSet

Dim myView As New DataView
myView = DSExcel.Tables(0).DefaultView

myView.Sort = "COLUMN_ONE "

NOTE: I debugged and checked the values of
DSExcel.Tables(0).Columns(0).ColumnName,
myView.Tables(0).Columns(0).ColumnName . both are "COLUMN_ONE "
In fact "COLUMN_ONE " is the name of first column in the spreadsheed
that I was uploading. In the quickwatch I saw there is a space
character at the end "COLUMN_ONE "


Please advise.

Thanks,

I guess the table you are assuming to be at position 0 is not there.
Why don't you try to look into its columns in debugger?
How do you load the table?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & developmentwww.rthand.com
Blog:http://cs.rthand.com/blogs/blog_with_righthand/



Hi, I was trying tosortdataviewusing the below process. It is
throwing exception. Please help.

Dim DSExcel1 As DataSet
DSExcel1 = New DataSet

Dim myView AsDataView
myView = DSExcel.Tables(0).DefaultView

myView.Sort= "Column_One"

DSExcel is a dataset with one table and 8 columns.

NOTE: "Column_One" is DSExcel.Tables(0).Columns(0).ColumnName

In the exception it says : Message "Cannot find columnColumn_One."
String

Thanks.
 
A

Amritha.Datta

Thanks you so much. This logic is working!!

It doesn't work because the last char isn't a space. Instead of 32 it has a
value of 160.
Thus, something like this will work:
view.Sort = "[" + ds.Tables[0].Columns[0].ColumnName + "]"

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & developmentwww.rthand.com
Blog:http://cs.rthand.com/blogs/blog_with_righthand/


Hi I am not able to attach the file. SO I am pasting the XML data
here.
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Table>
<COLUMN_ONE_x00A0_>R01AH0030D </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>O65LKDIAM </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDLKSIAMO65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AH1101 </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>U65LKDIAM </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>PPOLKDIAMU65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0269 </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>U65NR </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>PPONRU65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0069 </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>U65NR </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>THPNRU65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0019D </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>O65LKD </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDLKDMSPO65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0011D </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>O65NR </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDNRO65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0075D </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>O65NR </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDNRO65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0076D </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>O65NR </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDNRO65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01AS0011 </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>U65NR </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDNRU65 </COLUMN_FOUR_x00A0_>
</Table>
<Table>
<COLUMN_ONE_x00A0_>R01BH0030D </COLUMN_ONE_x00A0_>
<COLUMN_TWO_x00A0_>Z5M136354 </COLUMN_TWO_x00A0_>
<COLUMN_THREE_x00A0_>O65LKDIAM </COLUMN_THREE_x00A0_>
<COLUMN_FOUR_x00A0_>INDLKSIAMO65 </COLUMN_FOUR_x00A0_>
</Table>
</NewDataSet>
I don't have any idea why it is appending _x00A0_ .

Use DataSet.WriteXml method to create a file of serialized dataset and
send
it to me (or attach it to your reply).
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & developmentwww.rthand.com
Blog:http://cs.rthand.com/blogs/blog_with_righthand/

It returns the same error. Is there anything to do with
GetOleDbSchemaTable ?
Pls advise.
Thanks.
On Mar 26, 11:34 am, "Miha Markic [MVP C#]" <miha at rthand com>
wrote:
Try putting column name into square brackets, like myView.Sort =
"[COLUMN_ONE ]"
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & developmentwww.rthand.com
Blog:http://cs.rthand.com/blogs/blog_with_righthand/

Hi Miha Markic, Thanks for your response. Here is the code that
loads
the table.
Dim DSExcel As DataSet
Dim strSelect As String
strSelect = "Select from [" & strSheetName & "$]"
Dim objCmd As New OleDb.OleDbCommand(strSelect, Conn)
Dim daExcel As New OleDb.OleDbDataAdapter
DSExcel = New DataSet
daExcel.SelectCommand = objCmd
daExcel.Fill(DSExcel)
Dim DSExcel1 As DataSet
DSExcel1 = New DataSet
Dim myView As New DataView
myView = DSExcel.Tables(0).DefaultView
myView.Sort = "COLUMN_ONE "
NOTE: I debugged and checked the values of
DSExcel.Tables(0).Columns(0).ColumnName,
myView.Tables(0).Columns(0).ColumnName . both are "COLUMN_ONE "
In fact "COLUMN_ONE " is the name of first column in the spreadsheed
that I was uploading. In the quickwatch I saw there is a space
character at the end "COLUMN_ONE "
Please advise.
Thanks,
On Mar 26, 10:14 am, "Miha Markic [MVP C#]" <miha at rthand com>
wrote:
I guess the table you are assuming to be at position 0 is not
there.
Why don't you try to look into its columns in debugger?
How do you load the table?
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & developmentwww.rthand.com
Blog:http://cs.rthand.com/blogs/blog_with_righthand/

Hi, I was trying tosortdataviewusing the below process. It is
throwing exception. Please help.
Dim DSExcel1 As DataSet
DSExcel1 = New DataSet
Dim myView AsDataView
myView = DSExcel.Tables(0).DefaultView
myView.Sort= "Column_One"
DSExcel is a dataset with one table and 8 columns.
NOTE: "Column_One" is DSExcel.Tables(0).Columns(0).ColumnName
In the exception it says : Message "Cannot find
columnColumn_One."
String
Thanks.
 
A

Amritha.Datta

Thanks Cor. This logic is working as well. It is VB.NET code

C# code in VB.Net?

:)

Cor

Miha Markic said:
Try putting column name into square brackets, like myView.Sort =
"[COLUMN_ONE ]"
Hi Miha Markic, Thanks for your response. Here is the code that loads
the table.
Dim DSExcel As DataSet
Dim strSelect As String
strSelect = "Select from [" & strSheetName & "$]"
Dim objCmd As New OleDb.OleDbCommand(strSelect, Conn)
Dim daExcel As New OleDb.OleDbDataAdapter
DSExcel = New DataSet
daExcel.SelectCommand = objCmd
daExcel.Fill(DSExcel)
Dim DSExcel1 As DataSet
DSExcel1 = New DataSet
Dim myView As New DataView
myView = DSExcel.Tables(0).DefaultView
myView.Sort = "COLUMN_ONE "
NOTE: I debugged and checked the values of
DSExcel.Tables(0).Columns(0).ColumnName,
myView.Tables(0).Columns(0).ColumnName . both are "COLUMN_ONE "
In fact "COLUMN_ONE " is the name of first column in the spreadsheed
that I was uploading. In the quickwatch I saw there is a space
character at the end "COLUMN_ONE "
Please advise.
Thanks,
On Mar 26, 10:14 am, "Miha Markic [MVP C#]" <miha at rthand com>
wrote:
I guess the table you are assuming to be at position 0 is not there.
Why don't you try to look into its columns in debugger?
How do you load the table?
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & developmentwww.rthand.com
Blog:http://cs.rthand.com/blogs/blog_with_righthand/

Hi, I was trying tosortdataviewusing the below process. It is
throwing exception. Please help.
Dim DSExcel1 As DataSet
DSExcel1 = New DataSet
Dim myView AsDataView
myView = DSExcel.Tables(0).DefaultView
myView.Sort= "Column_One"
DSExcel is a dataset with one table and 8 columns.
NOTE: "Column_One" is DSExcel.Tables(0).Columns(0).ColumnName
In the exception it says : Message "Cannot find columnColumn_One."
String
Thanks.
 

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

Top