通过Button VB.NET更新数据

时间:2017-04-03 17:34:24

标签: sql asp.net vb.net

这是我的代码。我想更新“保存”按钮后面的数据,但是当我点击它时,它会刷新页面并且不显示更新的数据。它也不会在数据库中更新。

还有一种方法是不刷新,比如更新面板吗?

代码:

    Dim conn As SqlConnection
    Dim cmd As SqlCommand

    Dim fname As String
    Dim lname As String
    Dim DOB As String
    Dim PatientNumber As String
    Dim address1 As String
    Dim address2 As String
    Dim town As String
    Dim county As String
    Dim postcode As String
    Dim ContactNumber As String
    Dim Email As String


    PatientNumber = CInt(txtPatientNo.Text)
    fname = txtFName.Text
    lname = txtLName.Text
    DOB = txtDOB.Text
    address1 = txtAddress1.Text
    address2 = txtAddress2.Text
    town = txtTown.Text
    county = txtCounty.Text
    postcode = txtPostcode.Text
    ContactNumber = txtContact.Text
    Email = txtEmail.Text


    Dim cmdstring As String = "UPDATE PatientDetails SET FirstName = @FNAME, Surname = @LNAME, DateOfBirth = @DOB, Address = @ADDRESS1, Address2 = @ADDRESS2, Town = @TOWN, County = @COUNTY, Postcode = @POSTCODE, ContactNumber = @CONTACTNUMBER, EmailAddress = @EMAIL WHERE PatientNumber = @PatientNumber"

    conn = New SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=E:\myAppointments\App_Data\Database.mdf;Integrated Security=True")
    cmd = New SqlCommand(cmdstring, conn)

    cmd.Parameters.AddWithValue("@PATIENTNUMBER", PatientNumber)
    cmd.Parameters.AddWithValue("@FNAME", fname)
    cmd.Parameters.AddWithValue("@LNAME", lname)
    cmd.Parameters.AddWithValue("@DOB", DOB)
    cmd.Parameters.AddWithValue("@ADDRESS1", address1)
    cmd.Parameters.AddWithValue("@ADDRESS2", address2)
    cmd.Parameters.AddWithValue("@TOWN", town)
    cmd.Parameters.AddWithValue("@COUNTY", county)
    cmd.Parameters.AddWithValue("@POSTCODE", postcode)
    cmd.Parameters.AddWithValue("@CONTACTNUMBER", ContactNumber)
    cmd.Parameters.AddWithValue("@EMAIL", Email)

    conn.Open()

    cmd.ExecuteNonQuery()

    conn.Close()

0 个答案:

没有答案