Retrieving Column Information

callraheel

Well-known member
Joined
Dec 12, 2004
Messages
65
Location
London,UK
Programming Experience
1-3
Hello
I need to retrieve column information about a table and using MySQL.Net connector with MySQL and VB.NET.
The code i am using is as follows : (it adds the field names of the specific table in the list view items)

VB.NET:
[size=2][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] myConnection [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]New[/color][/size][size=2] MySqlConnection

[/size][size=2][color=#0000ff]Try

[/color][/size][size=2][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] rtnItems() [/size][size=2][color=#0000ff]As[/color][/size][size=2] ListViewItem, i [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]Integer[/color][/size][size=2] = 0

myConnection = Connection.AutoConnect

[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] myCommand [/size][size=2][color=#0000ff]As[/color][/size][size=2] MySqlCommand = myConnection.CreateCommand

myCommand.CommandText = "DESCRIBE st_info;"

[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] reader [/size][size=2][color=#0000ff]As[/color][/size][size=2] MySqlDataReader = myCommand.ExecuteReader(CommandBehavior.SchemaOnly)

myCommand.Dispose()

[/size][size=2][color=#0000ff]If[/color][/size][size=2] reader.HasRows = [/size][size=2][color=#0000ff]True[/color][/size][size=2] [/size][size=2][color=#0000ff]Then

[/color][/size][size=2][/size][size=2][color=#0000ff]While[/color][/size][size=2] reader.Read

[/size][size=2][color=#0000ff]ReDim[/color][/size][size=2] [/size][size=2][color=#0000ff]Preserve[/color][/size][size=2] rtnItems(i)

rtnItems(i).Text = reader.Item(0)

i += 1

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]While

[/color][/size][size=2][/size][size=2][color=#0000ff]Else

[/color][/size][size=2][/size][size=2][color=#008000]' create one and return...

[/color][/size][size=2][/size][size=2][color=#0000ff]ReDim[/color][/size][size=2] [/size][size=2][color=#0000ff]Preserve[/color][/size][size=2] rtnItems(0)

rtnItems(0).Text = "No Validation Settings Found"

[/size][size=2][color=#0000ff]Return[/color][/size][size=2] rtnItems

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If

[/color][/size][size=2][/size][size=2][color=#0000ff]Catch[/color][/size][size=2] ex [/size][size=2][color=#0000ff]As[/color][/size][size=2] Exception

msgbox(ex.Message)

[/size][size=2][color=#0000ff]Finally

[/color][/size][size=2]myConnection.Close()

myConnection.Dispose()

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]Try[/color][/size]
[size=2][color=#0000ff]
[/color][/size]

But the exception thrown is as follows becuase its not fetching columns or i might not be using appropriate code for that :
System.ArgumentNullException: Value cannot be null.

Parameter name: values

at System.Windows.Forms.ListViewItemCollection.AddRange(ListViewItem[] values)

at SIS.frmValidationSetup.frmValidationSetup_Load(Object sender, EventArgs e) in D:\Projects\SIS\frmValidationSetup.vb:line 121

at System.Windows.Forms.Form.OnLoad(EventArgs e)

at System.Windows.Forms.Form.OnCreateControl()

.....

So can anyone help me about about this...
Regards
Raheel

 
Back
Top