共計 2191 個字符,預計需要花費 6 分鐘才能閱讀完成。
今天就跟大家聊聊有關 VB.NET 修改數據存在多個 txtbox 時 SQL 語句的操作是怎樣的,可能很多人都不太了解,為了讓大家更加了解,丸趣 TV 小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
VB.NET 修改數據存在多個 txtbox 時,SQL 語句的操作
1. 一個 Button1 的 text 為查詢和一個 DataGridView1, 點擊查詢按鈕的代碼
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strConn = Data Source=192.168.1.110/orcl;User ID=test;Password=orcl
Dim dbcmd As OracleCommand
Dim dt = New DataTable(ds)
Dim dbConnection As OracleConnection
Try
dbConnection = New OracleConnection(strConn)
dbConnection.Open()
dbcmd = dbConnection.CreateCommand
dbcmd.CommandText = select * from student
Dim da As OracleDataAdapter = New OracleDataAdapter(dbcmd)
da.Fill(dt)
DataGridView1.DataSource = dt 這時候可以把 dt 的值直接賦值給 DataGridview1 控件
Catch ex As Exception
MsgBox(查詢數據庫出錯)
End Try
End Sub
2. 存在兩個 TextBox1.TextBox2, 文本框和一個按鈕, Button2, 按鈕 text 為修改, 點擊后的代碼
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim username, password As String
Dim temp, temp3 As String
If Len(TextBox1.Text.Trim) 0 Then
username = sname= + + TextBox1.Text.Trim + + ,
Else
username =
End If
If Len(TextBox2.Text.Trim) 0 Then
password = spwd= + + TextBox2.Text.Trim + + ,
Else
password =
End If
If Len(username) 0 And Len(password) 0 Then
temp = username + password
MsgBox(temp.Length)
temp = Mid(temp, 1, temp.Length – 3)
MsgBox(temp + temp)
MsgBox(current + DataGridView1.CurrentRow.Cells(1).Value)
Else
temp =
End If
Dim strConn = Data Source=192.168.1.110/orcl;User ID=test;Password=orcl
Dim dbcmd As OracleCommand
Dim dbConnection As OracleConnection
If username.Length = 0 And password = 0 Then
Try
dbConnection = New OracleConnection(strConn)
dbConnection.Open()
dbcmd = dbConnection.CreateCommand
Dim temp2 As String
temp2 = update student set + temp + where sname= + + DataGridView1.CurrentRow.Cells(1).Value +
dbcmd.CommandText = temp2
MsgBox(temp2)
dbConnection.BeginTransaction()
dbcmd.ExecuteNonQuery() 返回改動的 row 行數
Catch ex As Exception
MsgBox(修改失敗)
Exit Sub
End Try
Else
MsgBox(請填入要修改的參數)
End If
End Sub
看完上述內容,你們對 VB.NET 修改數據存在多個 txtbox 時 SQL 語句的操作是怎樣的有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注丸趣 TV 行業資訊頻道,感謝大家的支持。