Imports System.Data.SqlClient
Public DataBaseZhiXingJieGuo As Integer '用来返回数据库执行结果
Public cn As New SqlConnection("Data Source=100.6.0.35;Initial Catalog=mydata;User ID=sa;Password=123456;connect timeout=30")
Public Function DataModify(ByVal str As String) As Boolean '进行数据库修改操作
Dim cmdinsert As New SqlCommand
Try
cmdinsert.CommandText = str
cmdinsert.Connection = cn
If cn.State = ConnectionState.Closed Then cn.Open()
DataBaseZhiXingJieGuo = cmdinsert.ExecuteNonQuery() '用来返回执行的结果
'cn.Close()
Return True
Catch ex As Exception
MessageBox.Show(Err.Description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End Try
End Function
调用DataModify函数就可以了