请教向数据库标表中插入记录问题
本帖最后由 loishf 于 2012-10-12 18:50:25 编辑 在VS2010中,使用VB语言 数据库是以ADODB.Connection方式链接打开,请问如何向一个表里添加多条记录,数据库为SQL2000,求详解,谢谢!
[最优解释]
Public Shared Function ExecuteSqlTran(ByVal SqlStringList As List(Of String)) As Integer
If conn.State <> ConnectionState.Open Then
conn = New SqlConnection(CnStr)
conn.Open()
End If
Dim cmd As New SqlCommand
cmd.Connection = conn
Dim tx As SqlTransaction = cn.BeginTransaction
cmd.Transaction = tx
Try
Dim Counter As Integer = 0
For n = 0 To SqlStringList.Count
Dim sqlstr As String = SqlStringList(n)
If SqlStringList.ToString.Trim.Length > 1 Then
cmd.CommandText = sqlstr
Counter += cmd.ExecuteNonQuery
End If
Next
tx.Commit()
Return Counter
Catch ex As Exception
tx.Rollback()
Return 0
End Try
End Function
Dim ConnStr As String = "Provider=SQLOLEDB;Data Source..."
[其他解释]
你也得把错误的内容贴上来哈.
[其他解释]
你也得把错误的内容贴上来哈