السلام عليكم
اخواني انا عندي مشروع بسيط وهناك مشكلة في جلب بيانات من القاعدة نوعها mysql
عندما اضيف بيانات في قاعدة البيانات لا توجد مشكلة في الاضافه ولكن عندما اجلب البيانات يظهر هناك خطأ
Private Sub btnload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnload.Click 'again we do this because we do not yet declare this as global, but we do it for now beacause in later tutorial 'we will do the moduling and more on refactoring of codes con.ConnectionString = ("server=localhost;user id=root;password=;database=androidhive") Try con.Open() With cmd .Connection = con 'in this query it does simply selecting or getting all the user found in the database. .CommandText = "Select * from products" End With
Catch ex As Exception MsgBox(ex.Message)
End Try con.Close() da.Dispose() filltable(dtguser)
End Sub
هذا كود الخطأ
unable to convert mysql date/time value to system.datetime
وهذا الكود كامل المستخدم في الفورم
PHP كود :
'Description: This program can able to insert and read user form the MySQL Database using Visual Basic. 'Author: Joken Villanueva 'Date Created: Imports System.Data Imports MySql.Data.MySqlClient Public Class Manage_user Dim con As New MySqlConnection Dim result As Integer 'MySqlCommand It represents a SQL statement to execute against a MySQL Database Dim cmd As New MySqlCommand 'Represents a set of data commands and a database connection that 'are used to fill a dataset and update a MySQL database. This class cannot be inherited. Dim da As New MySqlDataAdapter
Private Sub btncreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncreate.Click 'this line of is simply we copy this one from our form con.ConnectionString = ("server=localhost;user id=root;password=;database=androidhive")
Try 'we open Connection con.Open()
With cmd .Connection = con .CommandText = "INSERT INTO `androidhive`.`products` (`pid`, `name`, `price`, `description`) " & _ "VALUES (NULL, '" & txtfullname.Text & "', '" & txtusername.Text & "', '" & txtpassword.Text & "');" 'in this line it Executes a transact-SQL statements against the connection and returns the number of rows affected result = cmd.ExecuteNonQuery 'if the result is equal to zero it means that no rows is inserted or somethings wrong during the execution If result = 0 Then MsgBox("Data has been Inserted!") Else MsgBox("Successfully saved!")
End If End With Catch ex As Exception MsgBox(ex.Message) End Try con.Close() End Sub
Private Sub btnload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnload.Click 'again we do this because we do not yet declare this as global, but we do it for now beacause in later tutorial 'we will do the moduling and more on refactoring of codes con.ConnectionString = ("server=localhost;user id=root;password=;database=androidhive") Try con.Open() With cmd .Connection = con 'in this query it does simply selecting or getting all the user found in the database. .CommandText = "Select * from products" End With
Catch ex As Exception MsgBox(ex.Message)
End Try con.Close() da.Dispose() filltable(dtguser)
End Sub ' this our sub procedure that well always used 'this beacause it always catch all the result query 'and it will display to any kind of visual basic containers like datagridview,listbox,listview, etc... Public Sub filltable(ByVal dtgrd As Object) 'declare a variable as new datatable Dim publictable As New DataTable Try 'Gets or sets an SQL statement or stored procedure used to select records in the database. da.SelectCommand = cmd da.Fill(publictable) dtgrd.DataSource = publictable dtgrd.Columns(0).Visible = False
da.Dispose()
Catch ex As Exception MsgBox(ex.Message)
End Try
End Sub
Private Sub Manage_user_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load