Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB
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 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
Posted
Updated 1-Sep-15 1:38am
v2

1 solution

If it's always the current date then you don't need to pass it through from your code, update your query to

SQL
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;

VB
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

VB
Dim nsn As String = txtNSN.Text
Dim title As String = txtTitle.Text
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900