我在msaccess
中有3列。 NAME | AGE | STATUS
。name
。 age
和required key value pair that you want
在数据库中有数据,Status列为空。如何使用vb.net和文本框将数据仅插入“状态”列。
答案 0 :(得分:0)
<强>第一强>
您需要设置连接。
e.g。
Imports System.Data.SqlClient
Imports System.Data
Public Class SQLTools
Inherits System.Windows.Forms.Form
Private Const SqlString As String = "Server= ;Database= ;User ID= ;Password= ;Integrated Security=SSPI;"
Private myConn As SqlConnection
Private myCmd As SqlCommand
Private myReader As SqlDataReader
Private Sub Conn()
myConn = New SqlConnection(SqlString)
End Sub
<强> SECOND 强>
现在您可以编写更新查询代码
Sub UpdateQuery(ByVal PK As Long, ByVal Val as String)
Dim Sql As String= "update TABLE_NAME set Status = @Val Where TABLE_PK = @PK"
myCmd = New SqlCommand(Sql, myConn)
myCmd.Parameters.Add("@PK", SqlDbType.Int).Value = PK
myCmd.Parameters.Add("@Val", SqlDbType.VarChar).Value = Val
myCmd.ExecuteNonQuery()
MsgBox("Update done!")
myConn.Close()
End Sub
<强> FINAL 强>
现在你必须叫你Sub传递你的Textbox值ByVal。
e.g。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
UpdateQuery(tablePk, TextBox1.Text)
End Sub