今天就跟大家聊聊有关VB.NET修改数据存在多个txtbox时sql语句的操作是怎样的,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。VB.net修改
今天就跟大家聊聊有关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语句的操作是怎样的有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注编程网数据库频道,感谢大家的支持。
--结束END--
本文标题: VB.NET修改数据存在多个txtbox时SQL语句的操作是怎样的
本文链接: https://lsjlt.com/news/68564.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0