今天就跟大家聊聊有關(guān)VB.NET修改數(shù)據(jù)存在多個txtbox時SQL語句的操作是怎樣的,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
成都創(chuàng)新互聯(lián)專注于法庫企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站,商城開發(fā)。法庫網(wǎng)站建設(shè)公司,為法庫等地區(qū)提供建站服務(wù)。全流程按需網(wǎng)站建設(shè),專業(yè)設(shè)計,全程項目跟蹤,成都創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
VB.NET修改數(shù)據(jù)存在多個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("查詢數(shù)據(jù)庫出錯")
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行數(shù)
Catch ex As Exception
MsgBox("修改失敗")
Exit Sub
End Try
' Else
' MsgBox("請?zhí)钊胍薷牡膮?shù)")
'End If
End Sub
看完上述內(nèi)容,你們對VB.NET修改數(shù)據(jù)存在多個txtbox時SQL語句的操作是怎樣的有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。