将用户输入从Textbox保存到Visual Studio 2012中的sql表

时间:2014-07-18 23:20:47

标签: asp.net vb.net textbox billing

我正在制作一个包含结算信息的电子商务结账页面,我想在文本框中保存用户输入的内容并将其保存到我的visual studio数据库中的customerB表中。单击按钮似乎没有做任何事情,我不知道还有什么可以工作。这似乎并不困难,我在youtube视频上找到了c#代码,但没有找到VB。

    Protected Sub btnAccountBilling_Click(ByVal sender As Object, ByVal e As EventArgs)         Handles btnAccountBilling.Click

    Dim strSQL As String
    Dim strConnectionString As String = System.Configuration.ConfigurationManager.ConnectionStrings("UStoreConnectionString").ConnectionString
    Dim connSQL As New SqlConnection(strConnectionString)
    Dim cmdSQL As New SqlCommand(strSQL, connSQL)

    cmdSQL = New SqlCommand("INSERT INTO CustomerB(FirstName, LastName, Address1, Address2, City, State, Zip, Phone, Email) VALUES (@FirstName, @LastName, @Address1, @Address2, @City, @State, @Zip, @Phone, @Email)", connSQL)

    cmdSQL.Parameters.AddWithValue("@Firstname", tbbFirstName.Text)
    cmdSQL.Parameters.AddWithValue("@Lastname", tbbLastName.Text)
    cmdSQL.Parameters.AddWithValue("@Address1", tbbAddress1.Text)
    cmdSQL.Parameters.AddWithValue("@Address2", tbbAddress2.Text)
    cmdSQL.Parameters.AddWithValue("@City", tbbCity.Text)
    cmdSQL.Parameters.AddWithValue("@State", ddlbState.Text)
    cmdSQL.Parameters.AddWithValue("@Zip", tbbZip.Text)
    cmdSQL.Parameters.AddWithValue("@Phone", tbbPhone.Text)
    cmdSQL.Parameters.AddWithValue("@Email", tbbEmail.Text)

    connSQL.Open()
    cmdSQL.ExecuteNonQuery()
    connSQL.Close()

End Sub

我的所有文本框值和按钮都已正确命名,所以我不确定是什么问题

0 个答案:

没有答案