Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 有人知道如何在vb.net asp中使用文本框更新数据库吗?_Asp.net_Sql_Vb.net_Textbox_Updating - Fatal编程技术网

Asp.net 有人知道如何在vb.net asp中使用文本框更新数据库吗?

Asp.net 有人知道如何在vb.net asp中使用文本框更新数据库吗?,asp.net,sql,vb.net,textbox,updating,Asp.net,Sql,Vb.net,Textbox,Updating,请帮帮我。我有一个数据源,它在页面加载时填充文本框,以便像这样更新它们……这是可行的,但更新不可行 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim dv As DataView = DirectCast(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView) F

请帮帮我。我有一个数据源,它在页面加载时填充文本框,以便像这样更新它们……这是可行的,但更新不可行

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim dv As DataView = DirectCast(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)
    For Each drv As DataRowView In dv
        txtCompName.Text = drv("companyName").ToString()
        txtAddressLine1.Text = drv("addressLine1").ToString()
        txtAddressLine2.Text = drv("addressLine2").ToString()
        txtTown.Text = drv("companyTown").ToString()
        txtCompanyPostCode.Text = drv("customerPostcode").ToString()
        txtCompanyTelephone.Text = drv("companyTelephone").ToString()
        txtCompanyWebAdd.Text = drv("webAddress").ToString()
        ' ddlCompanyStatus.Text = drv("companyStatus").ToString()
        ddlQuoteStatus.Text = drv("companyQuoteStatus").ToString()
        txtCompanyNotes.Text = drv("companyNotes").ToString()
        txtRegion.Text = drv("companyRegion").ToString()
        ddlLeadSource.Text = drv("leadSource").ToString()
        txtSICCode.Text = drv("SICCode").ToString()
        ' txt.Text = drv("dateEntered").ToString()
        ddlEnterMadeBy.Text = drv("employeeAddedCustomer").ToString()
        ddlAddressType.Text = drv("addressType").ToString()
        txtCompBecameCustomer.Text = drv("dateBecameACustomer").ToString()


        lblActivityDate.Text = Date.Now
        lblActivityTime.Text = TimeOfDay

    Next
End Sub
这是数据源,我添加了一条UPDATESQL语句,只是为了尝试另一种方法

</table>   <asp:SqlDataSource ID="SqlDataSource1" OnUpdating=" btnAddCustomer_Click" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [customerTable] WHERE ([customerId] = @customerId)" UpdateCommand="Update customerTable set companyName = @companyName , addressLine1 = @addressLine1, addressLine2 = @addressLine2, companyTown = @companyTown, customerPostcode = @customerPostcode, companyTelephone = @companyTelephone, webAddress = @webAddress, companyStatus = @companyStatus, companyQuoteStatus = @companyQuoteStatus, companyNotes = @companyNotes, companyRegion = @companyRegion, leadSource = @leadSource, SICCode = @SICCode, employeeAddedCustomer = @employeeAddedCustomer, addressType = @addressType, dateBecameACustomer = @dateBecameACustomer where customerId =@customerId
">
    <SelectParameters>
        <asp:QueryStringParameter DefaultValue="0" Name="customerId" QueryStringField="customerId" Type="Int32" />
    </SelectParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="companyName" />
                        <asp:Parameter Name="addressLine1" />
                        <asp:Parameter Name="addressLine2" />
                        <asp:Parameter Name="companyTown" />
                        <asp:Parameter Name="customerPostcode" />
                        <asp:Parameter Name="companyTelephone" />
                        <asp:Parameter Name="webAddress" />
                        <asp:Parameter Name="companyStatus" />
                        <asp:Parameter Name="companyQuoteStatus" />
                        <asp:Parameter Name="companyNotes" />
                        <asp:Parameter Name="companyRegion" />
                        <asp:Parameter Name="leadSource" />
                        <asp:Parameter Name="SICCode" />
                        <asp:Parameter Name="employeeAddedCustomer" />
                        <asp:Parameter Name="addressType" />
                        <asp:Parameter Name="dateBecameACustomer" />
                        <asp:Parameter Name="customerId" />
                    </UpdateParameters>
</asp:SqlDataSource>
我还尝试使用以下方法

    'cmd.CommandText = "Update customerTable set companyName = @companyName where customerId = 1" ' & strCustomerId

    ' cmd.CommandText = "Update customerTable set companyName = '" & txtCompName.Text & "' "
    'cmd.Parameters.Add(New SqlParameter("@companyName", txtCompName.Text))

    'cmd.Parameters.Add(New SqlParameter("@companyName", DirectCast(txtCompName, TextBox).Text))

---------------------------------------------------------------------------------------------- 
addressLine1, addressLine2, companyTown, customerPostcode, companyTelephone, webAddress, companyStatus, companyQuoteStatus, companyNotes, companyRegion, leadSource, SICCode, dateEntered, employeeAddedCustomer)VALUES('" + strName + "','" + strAddressLine1 + "','" + strAddressLine2 + "','" + strCompanyTown + "','" + strcustomerPostcode + "','" + strcompanyTelephone + "','" + strwebAddress + "','" + strcompanyStatus + "','" + strcompanyQuoteStatus + "','" + strcompanyNotes + "' ,'" + strRegion + "' ,'" + strLeadSource + "' ,'" + strSICCode + "' ,'" + strDateCompanyEntered + "' ,'" + employeeAddedCustomer + "')"

请格式化你的问题。还有,问题是什么?您是否收到错误消息?您收到的是什么
错误
?数据库中没有错误和更新
    'cmd.CommandText = "Update customerTable set companyName = @companyName where customerId = 1" ' & strCustomerId

    ' cmd.CommandText = "Update customerTable set companyName = '" & txtCompName.Text & "' "
    'cmd.Parameters.Add(New SqlParameter("@companyName", txtCompName.Text))

    'cmd.Parameters.Add(New SqlParameter("@companyName", DirectCast(txtCompName, TextBox).Text))

---------------------------------------------------------------------------------------------- 
addressLine1, addressLine2, companyTown, customerPostcode, companyTelephone, webAddress, companyStatus, companyQuoteStatus, companyNotes, companyRegion, leadSource, SICCode, dateEntered, employeeAddedCustomer)VALUES('" + strName + "','" + strAddressLine1 + "','" + strAddressLine2 + "','" + strCompanyTown + "','" + strcustomerPostcode + "','" + strcompanyTelephone + "','" + strwebAddress + "','" + strcompanyStatus + "','" + strcompanyQuoteStatus + "','" + strcompanyNotes + "' ,'" + strRegion + "' ,'" + strLeadSource + "' ,'" + strSICCode + "' ,'" + strDateCompanyEntered + "' ,'" + employeeAddedCustomer + "')"