Unable to sort Dataview

  • Thread starter Thread starter Amritha.Datta
  • Start date Start date
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.
 
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 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
 
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
 
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.
 
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
 
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.
 
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
 
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# 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.
 
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.
 
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.
 
Back
Top