将数据保存到具有来自各种其他表的数据的SQL数据库。 [英] Saving Data to SQL database having data from various other tables.

查看:47
本文介绍了将数据保存到具有来自各种其他表的数据的SQL数据库。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好。



我正在开发一个定制的物流应用程序,在我的一个表格中,我有4个下拉列表,一个文本框和gridview。四个下拉列表中填充了来自四个不同表格的数据,而文本框则要求用户输入数据。



我发现的问题是,当我去保存到需求表时,它没有保存任何数据。



下拉列表如下

货件号 - 从表ShipmentNumbers中显示货件编号

客户 - 列出所有客户

品牌 - 列出所有品牌

货币 - 列出所有当前货币。

季节 - 用户的文本框进入相关季节,例如。 SU15



以下代码是使用参数的当前插入声明。



Good afternoon

I am developing a custom made logistics application and in one of my forms i have 4 dropdown lists a textbox and gridview. The four dropdowns are populated with data from four different tables, while the textbox requires that data is inputed by the user.

My problem that i am finding is that when i go to save to the require table it is not saving any data.

The Dropdowns are a follows
Shipment No - display shipment number from table ShipmentNumbers
Client - lists all the clients
Brand - lists all the Brands
Currency - lists all the currenct currency's.
Season - textbox for user to enter relevant season eg. SU15

The below code is the Current Insert Statement using parameters.

Public Sub InsertShipmentNoDetails(ByVal RegShipmentID As Integer, ByVal ClientID As Integer, ByVal Season As String, ByVal BrandID As Integer, ByVal CurrencyID As Integer)
       'This inserts a new transit document to the database table in question
       'A set of parameters are passed then connected to the command object
       Dim myCommand As New SqlCommand()

       myCommand.Connection = SQLCon

       myCommand.CommandText = "INSERT INTO RegisterShipmentNoDetails(RegShipmentID, ClientID, Season, BrandID, CurrencyID)values(@RegShipmentID,@ClientID,@Season,@BrandID,@CurrencyID)"
       'Parameters are passed and connected to the Command Object

       myCommand.Parameters.AddWithValue("@RegShipmentID", RegShipmentID)
       myCommand.Parameters.AddWithValue("@ClientID", ClientID)
       myCommand.Parameters.AddWithValue("@Season", Season)
       myCommand.Parameters.AddWithValue("@BrandID", BrandID)
       myCommand.Parameters.AddWithValue("@Currency", CurrencyID)

       'Here the command on the database is executed.
       myCommand.ExecuteNonQuery()

   End Sub





然后从保存按钮调用上述方法,如下所示。





The above method is then called from the save button as follows.

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
       'Validate if textbox is empty or not
       If ValidateData(txtSeason) = False Then
           ' MessageBox.Show("Please enter Required Textbox Details", ApplicationName, MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk)

           Exit Sub
       End If

       Try
           mySQL.InsertShipmentNoDetails(txtSeason.Text, cboBrand.SelectedValue, cboClient.SelectedValue, cboCurrency.SelectedValue, cboShipmentNo.SelectedValue)

       Catch ex As Exception
           MessageBox.Show("Register Shipment Details Could Not Be Inserted," & ex.Message, ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error)
           Exit Sub
       End Try

       MessageBox.Show(" Register Shipments Details Successfully Inserted", ApplicationName, MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
       'Gridview is loaded
       dvShipmentRegister.Table = mySQL.LoadShipmentNoDetails()

   End Sub





如果有人在上面的代码中解释我做错了什么或哪里出错,我将不胜感激。



谢谢。



Would appreciate if someone would explain what or where i am doing wrong in the above code.

Thanks.

推荐答案

整个代码是不包括在你的帖子中所以这有点猜测,但是:

- ValidateData(txtSeason)由于某种原因返回false,在这种情况下你不显示任何消息

- SQLCon指向错误的数据库

- 现有连接的状态是错误的

- 您有持续的交易,但您没有提交等等



任何方式,最好打开调试器并逐行完成代码。这样您就可以立即查明问题的根源。
The whole code isn't included in your post so this is somewhat guessing, but:
- ValidateData(txtSeason) returns false for some reason, you don't show any message in such case
- SQLCon points to a wrong database
- state of the already existing connection is wrong
- you have a ongoing transaction but you don't commit and so on

Any way, it's best to open the debugger and go through the code, line-by-line. This way you'll pinpoint the source of the problem in no time.


这篇关于将数据保存到具有来自各种其他表的数据的SQL数据库。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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