VS 2005 中用 vb写软件 如何通过SqlDataAdapter insert 数据库中的表,我是新手

2024-12-25 16:34:07
推荐回答(1个)
回答1:

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函数就可以了