如果是我的话,我会这样用:
Dim strcon As String = "***********************************************"'数据库连接字串
' Dim strcmd As String
Dim sqlcn As SqlClient.SqlConnection = New SqlClient.SqlConnection(strcon)
sqlcn.Open()
Dim dsTemp01 As DataSet
Dim daTemp01 As SqlClient.SqlDataAdapter
Dim rw01 As DataRow
Dim daTempComm01 As SqlClient.SqlCommandBuilder
Dim z As Integer
dsTemp01 = New DataSet
daTemp01 = New SqlClient.SqlDataAdapter("select * from [testData] where [test1]='" & CStr(Trim(TextBox1.Text)) & "';", sqlcn)
daTemp01.Fill(dsTemp01, "datalist") 'dsTemp01数据集中数据表名
z = dsTemp01.Tables(0).Rows.Count
If z > 0 Then
MsgBox("該用戶名已存在!")
Else
'当然这里可以用插入语句,不一定要用添加新行的方法
rw01 = dsTemp01.Tables("datalist").NewRow
rw01("test1") = CStr(Trim(TextBox1.Text))
dsTemp01.Tables("datalist").Rows.Add(rw01)
daTempComm01 = New SqlClient.SqlCommandBuilder(daTemp01)
daTemp01.Update(dsTemp01, "datalist")
MsgBox("申請成功,請登入!")
End If
Dim strcon As String = "***********************************************"'数据库连接字串
' Dim strcmd As String
Dim sqlcn As SqlClient.SqlConnection = New SqlClient.SqlConnection(strcon)
sqlcn.Open()
Dim dsTemp01 As DataSet
Dim daTemp01 As SqlClient.SqlDataAdapter
Dim rw01 As DataRow
Dim daTempComm01 As SqlClient.SqlCommandBuilder
Dim z As Integer
dsTemp01 = New DataSet
daTemp01 = New SqlClient.SqlDataAdapter("select * from [testData] where [test1]='" & CStr(Trim(TextBox1.Text)) & "';", sqlcn)
daTemp01.Fill(dsTemp01, "datalist") 'dsTemp01数据集中数据表名
z = dsTemp01.Tables(0).Rows.Count
If z > 0 Then
MsgBox("該用戶名已存在!")
Else
'当然这里可以用插入语句,不一定要用添加新行的方法
rw01 = dsTemp01.Tables("datalist").NewRow
rw01("test1") = CStr(Trim(TextBox1.Text))
dsTemp01.Tables("datalist").Rows.Add(rw01)
daTempComm01 = New SqlClient.SqlCommandBuilder(daTemp01)
daTemp01.Update(dsTemp01, "datalist")
MsgBox("申請成功,請登入!")
End If
一个人只有一个心脏,却有两个心房。一个住着快乐;一个住着悲伤。不要笑得太大声,不然会吵醒旁边的悲伤