2014-10-05 65 views

回答

0

使用對象的字符串表示形式並將此字符串存儲到數據庫中。 JSON可能是你在這裏有用,JSON.net常用...

0

這裏是在MySQL數據庫中插入一條記錄代碼:

比方說,你有一個名爲(MYDB)一個MySQL數據庫和表稱爲(myTable)。 有兩個字段在myTable的:ID(int)和TextBoxData(文本)

Imports MySql.Data.MySqlClient 
Imports System.Data.OleDb 

Public Class Form1 
Dim conn As New MySqlConnection 
Sub connect() 
Dim DatabaseName As String = "myDB" 
Dim server As String = "ip address here" 
Dim userName As String = "username here" 
Dim password As String = "password here" 
If Not conn Is Nothing Then conn.Close() 
conn.ConnectionString = String.Format("server={0}; user id={1}; password={2}; database={3}; pooling=false", server, userName, password, DatabaseName) 
Try 
conn.Open() 

MsgBox("Connected") 
Catch ex As Exception 
MsgBox(ex.Message) 
End Try 
conn.Close() 
End Sub 
End Class 

「下面的代碼被用於寫入MySQL數據庫: 嘗試 conn.Open() 抓住前作爲異常

End Try 

Dim cmd As New MySqlCommand(String.Format("INSERT INTO `myTable` (`ID` , `TextBoxData`) VALUES ('{0}' , '{1}')", "", TextBox1.Text)) 
cmd.ExecuteNonQuery() 

conn.Close() 

來源:VB.NET connect to MySql Server