CommandBehavior.KeyInfo - iskey info is always false with provider my MySqlProv.3.0)

C

chris

Hello,

I am trying to find the name of the keyfield of a table in mysql. (visual
studio 2003 en iis5.0 en een web pagina asp.net)

I use myreader = cmd.ExecuteReader(CommandBehavior.SchemaOnly Or
CommandBehavior.KeyInfo)

and show all info in a grid.

I notice that de "iskey" property is always set to False (even of all the
field , included the actual key field)

I use Provider=MySqlProv.3.0 (Because it is a mysql database accessed
through oledb)

In de mysql console the field "ID" of the table is marked with the 'key'
icon and even autoincrement is turned on .But it remains "iskey" = false

What could be the problem ?

Is there another way to find the name of the keyfield of a table ?

Thanks for any help.

Christine





Imports System.Data.OleDb

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim cn As New OleDbConnection()

Dim cmd As New OleDbCommand()

Dim schemaTable As DataTable

Dim myReader As OleDbDataReader

Dim myField As DataRow

Dim myProperty As DataColumn

Dim sleutelveld As String

Dim aantalKeys As Integer = 0

'Open a connection to MYSQL

cn.ConnectionString = "Location=127.0.0.1;Provider=MySqlProv.3.0;User
ID=root;Integrated Security=;Data Source=ims-dbtest;Extended
Properties=;Password="

cn.Open()

'Retrieve records from the table into a DataReader.

cmd.Connection = cn

cmd.CommandText = "SELECT * FROM TestChris"

myReader = cmd.ExecuteReader(CommandBehavior.SchemaOnly Or
CommandBehavior.KeyInfo)

'Retrieve column schema into a DataTable.

schemaTable = myReader.GetSchemaTable()

DataGrid1.DataSource = schemaTable

DataGrid1.AutoGenerateColumns = True

DataGrid1.DataBind()

'For each field in the table...

For Each myField In schemaTable.Rows

'For each property of the field...

For Each myProperty In schemaTable.Columns

'Display the field name and value.

If myProperty.ColumnName.ToLower = "iskey" Then

If myField(myProperty).ToString = "True" Then

sleutelveld = myField("columnname").ToString

aantalKeys = aantalKeys + 1

End If

End If

Next

Next

'Always close the DataReader and Connection objects.

myReader.Close()

cn.Close()

End Sub
 

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