如何将文本框中的数据插入SQL服务器? VB [英] How to insert data from textbox into SQL server ? VB

查看:66
本文介绍了如何将文本框中的数据插入SQL服务器? VB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点击提交按钮后,我的页面刷新但没有任何反应。数据库中也没有记录。不知道哪里出了问题。没有错误信息



我尝试过:



 Dim connectionString As String 
Dim connection As SqlConnection
Dim SQLcmd As New SqlCommand
Dim logdate As Date = Date.Today
connectionString = ConfigurationManager.ConnectionStrings(BARCODEConnectionString) .ToString
connection = New SqlConnection(connectionString)

尝试
connection.Open()
Catch ex As Exception
SQLcmd.CommandText =INSERT INTO PickingList([USRID],[PICKINGLIST_ID],[LOGDATE])VALUES('& Convert.ToInt32(PickerID.Text)&','& Convert.ToInt32(PickListID.Text)&', now())
SQLcmd.ExecuteNonQuery()
lblerror.Text =提交失败。请再试一次。
结束尝试
如果connection.State = 1则

lblerror.Text =connected
结束如果

解决方案

嗯......你在catch中有更新命令。

如果连接无法打开,它只会尝试更新!

After I click on submit button my page refresh but nothing happen. There is no record in the database also. Not sure where went wrong. no error message

What I have tried:

Dim connectionString As String
           Dim connection As SqlConnection
           Dim SQLcmd As New SqlCommand
           Dim logdate As Date = Date.Today
           connectionString = ConfigurationManager.ConnectionStrings("BARCODEConnectionString").ToString
           connection = New SqlConnection(connectionString)

           Try
               connection.Open()
               Catch ex As Exception
               SQLcmd.CommandText = "INSERT INTO PickingList([USRID],[PICKINGLIST_ID],[LOGDATE]) VALUES ('" & Convert.ToInt32(PickerID.Text) & "','" & Convert.ToInt32(PickListID.Text) & "', now())"
               SQLcmd.ExecuteNonQuery()
               lblerror.Text = "Fail to submit. Please try again."
           End Try
           If connection.State = 1 Then

               lblerror.Text = "connected"
           End If

解决方案

Um... you have the update command in the catch.
It will only try the update if the connection fails to open!


这篇关于如何将文本框中的数据插入SQL服务器? VB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆