您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關VB.NET修改數據存在多個txtbox時SQL語句的操作是怎樣的,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
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語句的操作是怎樣的有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。