473,409 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

binding a mysql table on vb05 datagridview error

13
Im trying to bind a table in mysql containing a mysql date field in a datagridview in vb.net 05. When i only select fields containing non-dates it works, but once i add a date field it generates this error:

Unable to convert MySQL date/time value to System.DateTime


Any work around for this?

Thanks in advance. ;)
Feb 2 '08 #1
4 1937
thelner
13
Can anybody help me please...
Feb 3 '08 #2
I've run into the same problem. I've tried to dynamically create a List View. My tests work, but I think I still prefer a Data Grid View.
Apr 3 '08 #3
I don't know if this helps you, but I wound up using a ListView to show the data. It uses a TreeView to show the table names.

Imports System.Data.OleDb
Imports MySQLDriverCS
Imports System.Data

Public Class Main
Private MyConnectionString As String = ""
Private Database As String = ""
Private Sub FetchTableList()
Dim mVals(255) As String
Dim mBuiltCon As String = Nothing
Dim i As Integer = 0
Dim myConnection As New MySQLConnection(MyConnectionString) '(mBuiltCon)
myConnection.Open()
Dim Cmd As New MySQLCommand("SHOW TABLES FROM " + Database, myConnection)
Dim RD As MySQLDataReader = Cmd.ExecuteReader()
Try
If RD.HasRows Then
While RD.Read()
mVals(i) = RD.GetString(0)
trvTableList.Nodes.Add(mVals(i))
i += 1
End While
End If
Cmd.Dispose()
RD.Close()
Catch ex As Exception
MsgBox("Error while executing: (" & Cmd.CommandText & ")" & _
vbCrLf & "Msg: " & ex.Message.ToString, MsgBoxStyle.Exclamation, "UCM")
Finally
If myConnection.State = ConnectionState.Open Then myConnection.Close()
mBuiltCon = Nothing
End Try
End Sub
Private Sub FetchTableColumns(ByVal TableName As String)
Dim mVals(255) As String
Dim mBuiltCon As String = Nothing
Dim i As Integer = 0
Dim myConnection As New MySQLConnection(MyConnectionString)
myConnection.Open()
Dim Cmd As New MySQLCommand("SHOW COLUMNS FROM " & TableName & " FROM " + Database, myConnection)
Dim RD As MySQLDataReader = Cmd.ExecuteReader()
Try
If RD.HasRows Then
While RD.Read()
mVals(i) = RD.GetString(0)
lstSQLList.Columns.Add(RD.GetString(0), 100, HorizontalAlignment.Left)
i += 1
End While
End If
Cmd.Dispose()
RD.Close()
Catch ex As Exception
MsgBox("Error while executing: (" & Cmd.CommandText & ")" & _
vbCrLf & "Msg: " & ex.Message.ToString, MsgBoxStyle.Exclamation, "UCM")
Finally
If myConnection.State = ConnectionState.Open Then myConnection.Close()
mBuiltCon = Nothing
FetchTableData(TableName)
End Try
End Sub
Private Sub FetchTableData(ByVal TableName As String) ', ByVal TotalColumns As Integer)
Dim mVals(255) As String
Dim mBuiltCon As String = Nothing
Dim myConnection As New MySQLConnection(MyConnectionString) '(mBuiltCon)
myConnection.Open()
Dim Cmd As New MySQLCommand("SELECT * FROM " & TableName, myConnection)
Dim RD As MySQLDataReader = Cmd.ExecuteReader()
Try
If RD.HasRows Then
While RD.Read()
Dim Column0 As String = IIf(IsDBNull(RD(0)), "", RD(0))
Dim item As New ListViewItem(Column0)
For i = 1 To RD.FieldCount - 1
If IsDBNull(RD(i)) Then
item.SubItems.Add("")
Else
item.SubItems.Add(RD(i))
End If
Next
lstSQLList.Items.Add(item)
End While
End If
Cmd.Dispose()
RD.Close()
Catch ex As Exception
MsgBox("Error while executing: (" & Cmd.CommandText & ")" & _
vbCrLf & "Msg: " & ex.Message.ToString, MsgBoxStyle.Exclamation, "UCM")
Finally
If myConnection.State = ConnectionState.Open Then myConnection.Close()
mBuiltCon = Nothing
End Try
End Sub
Private Sub trvTableList_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles trvTableList.AfterSelect
lstSQLList.Columns.Clear()
lstSQLList.Items.Clear()
FetchTableColumns(e.Node.Text)
End Sub
Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FetchTableList()
End Sub
End Class
Apr 4 '08 #4
Better solution, a friend sent me this link and it fixed all my problems. Try this driver.

http://dev.mysql.com/downloads/connector/net/5.0.html
Apr 4 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: JSantora | last post by:
Essentially, InsertAT is broken! For the past couple of hours, I've been getting this "Parameter name: '-2147483550' is not a valid value for 'index'." error. Apparently, its caused by having...
3
by: nvx | last post by:
Hello everyone... Just for the record, I'm a newbie to this data binding thing... In my C# application I need to bind a cell of an Access database table to a multiline TextBox. How should I do...
2
by: Nathan | last post by:
Hi, I have a datagridview bound to a List of objects (ObjectA). Each ObjectA contains an ObjectB property. Class ObjectA { public ObjectB objB {} }
2
by: Rich | last post by:
Hello, Following an example at http://www.vb-tips.com/dbpages.aspx?IA=DG (by Cor Lightert and Ken Tucker) on binding a dataRelation to a Datagridview for sqlClient, I was able to view rows...
2
by: plmanikandan | last post by:
Hi, I am using .net framework2.0,Visual Studio 2005.I need to bind the hash table to datagridview.Is it possible I am having class Person class person { public int no; public string name; }
1
by: kristian | last post by:
Hi all I have a simple form with not much more than a datagridview control, and want to show and edit the contents of a table in my mysql table. So far I have managed to set the db table as a...
3
by: =?Utf-8?B?Sm9obiBCdW5keQ==?= | last post by:
New to databinding in vs2005, I always did it manually in 2003. I have no problem loading comboboxes, and a change in that combobox changes the data in the textboxes but I can not figure out a way...
11
by: dave18 | last post by:
Hello all! I found a solution to my original question, but there's still so much I don't understand about it, I thought I'd give this forum a try. At the very least, maybe it will help someone...
1
by: GS | last post by:
I am perplexed . I thought it is easy to fix the binding error on cvtDtFrom. I only used the cvtDtFrom a couple of places but I found out the error occurred before form loading. I tried...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.