如何在我的数据库中保存创建日期 [英] How to save the date of creation in my database
问题描述
你好,
我为我的部门创建了一个项目,以加快我们的工作,我使用VB.net 2008,我创建了一个表格,包含要保存在数据库表中的标签文本框。另外,我创建了许多采石场将数据保存在一个名为Item的表中,但我的主要问题是当我在项目表中定义日期时,vb.net会拒绝它,所以我决定在这个网站上询问。
另外,我想保存用户输入的MFR列表。你能帮我这个吗?
代码如下:
Hello There,
I have created a Project for my department to speed up our work and I am using VB.net 2008 and I have created a form that contains labels textboxes to be saved in the database table. Also, I have created many quarries to save the data in a table called Item, but my main problem is when I define the date to post it in the item table the vb.net refuse It so I have decided to ask in this website.
Also, I want to save a list of MFR witch its going to be entered by the user. can you help me with this as well ?
The codes as the following:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim a As String = TextBox1.Text 'N-S-N Number
Dim b As String = TextBox6.Text 'Title
Dim c As String = TextBox2.Text 'Description
Dim d As String = TextBox3.Text 'Specification
Dim f As String = TextBox4.Text 'Guarantee
Dim g As String = Listbox1.text 'Listbox1 approve MFR
Dim h As String = 1 'RadioButton1.Checked EDD
Dim i As string = 2 'RadioButton2.Checked WDD
Dim j As String = 3 'RadioButton3.Checked Other
Dim dt As Date = Today()
If (a = Nothing) Or (b = Nothing) Or (c = Nothing) Or (d = Nothing) Or (f = Nothing) Or (g = Nothing) Then
MsgBox("Please Fill the Fields")
ElseIf (ItemTableAdapter1.Checkitem(TextBox1.Text) = Nothing) And (RadioButton1.Checked = True) Then
'If yes save in Database
Select Case (MsgBox("Are you sure you want to save this item for EDD", MsgBoxStyle.YesNo))
Case MsgBoxResult.Yes
ItemTableAdapter1.AddItem(a, b, c, d, f, g, h, dt)
MsgBox("A new item has been added")
Case MsgBoxResult.No
MsgBox("Item not Saved")
End Select
ElseIf (ItemTableAdapter1.Checkitem(TextBox1.Text) = Nothing) And (RadioButton2.Checked = True) Then
Select Case (MsgBox("Are you sure you want to save this item for WDD", MsgBoxStyle.YesNo))
Case MsgBoxResult.Yes
ItemTableAdapter1.AddItem(a, b, c, d, f, g, i, dt)
AddItem2.Show()
Me.Hide()
Case MsgBoxResult.No
MsgBox("Item not Saved")
End Select
ElseIf (ItemTableAdapter1.Checkitem(TextBox1.Text) = Nothing) And (RadioButton3.Checked = True) Then
Select Case (MsgBox("Are you sure you want to save this item for Other", MsgBoxStyle.YesNo))
Case MsgBoxResult.Yes
ItemTableAdapter1.AddItem(a, b, c, d, f, g, j, dt)
AddItem2.Show()
Me.Hide()
Case MsgBoxResult.No
MsgBox("Item not Saved")
End Select
Else
MsgBox("This Item Is already exist")
End If
End Sub
INSERT INTO项目
([NS-NNumber],标题,描述,规格,保证,MFR,董事会,日期)
VALUES('@NS -NNumber',@ Title,@ Description,@ Specification,@ Guarantee,@ MFR,@ Directorate,@ Date)
我将表中的格式更改为datetime
INSERT INTO Item
([N-S-NNumber], Title, Description, Specification, Guarantee, MFR, Directorate, Date)
VALUES ('@N-S-NNumber',@Title,@Description,@Specification,@Guarantee,@MFR,@Directorate,@Date)
And I changed the format in the table to datetime
推荐答案
如果它始终是当前日期,那么您不需要从代码中传递它,将查询更新为
If it's always the current date then you don't need to pass it through from your code, update your query to
INSERT INTO Item
([N-S-NNumber], Title, Description, Specification, Guarantee, MFR, Directorate, [Date])
VALUES ('@N-S-NNumber',@Title,@Description,@Specification,@Guarantee,@MFR,@Directorate,GetDate())
在附注中;
On a side-note;
Dim a As String = TextBox1.Text 'N-S-N Number
Dim b As String = TextBox6.Text 'Title
而不是添加注释来说明文本框包含的内容你应该给你的控件和变量正确的名字
Rather than adding a comment to say what the textbox contains you should give your controls and variables proper names
Dim nsn As String = txtNSN.Text
Dim title As String = txtTitle.Text
这篇关于如何在我的数据库中保存创建日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!