Advertisement
NAK

AddMDBRecord1

NAK
Apr 29th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.56 KB | None | 0 0
  1. Public Class Tambah_Maklumat
  2.  
  3.     Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  4.         If txtRef.Text = "" Or txtQty.Text = "" Or txtYear.Text = "" Or txtAuthor.Text = "" Or txtPrice.Text Or
  5.         txtPub.Text = "" Then          
  6.             MsgBox("please fill in the blank", MsgBoxStyle.Information) ' <- move this line to a new line
  7.                                                                         ' ^^^^^^^^^^^^^NEW COMMENT^^^^^^^^^^^^
  8.         Else '<--- why at this session its error?? can u explain it say "Error   1       'Else' must be preceded by a matching 'If' or 'ElseIf'. C:\Users\Zazila\Documents\Visual Studio 2012\Projects\LybrarySystem\LybrarySystem\Form2.vb      7       1       LybrarySystem"
  9.  
  10.  
  11.             If MessageBox.Show("confrim add?", "Add books", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
  12.  
  13.                 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  14.                 Dim con As New OleDb.OleDbConnection
  15.                 Dim cmdinfo As New OleDb.OleDbCommand
  16.                 Dim dbProvider As String
  17.                 Dim dbSource As String
  18.  
  19.                 dbProvider = "Provider=Microsoft.Jet.OLEDB.4.0; "
  20.                 dbSource = "data source=" & AppDomain.CurrentDomain.BaseDirectory & "Database2.mdb"
  21.  
  22.                 con.ConnectionString = dbProvider & dbSource
  23.  
  24.                 With cmdinfo ' this simply saves us having to type in cmdinfo every time
  25.                     .CommandType = CommandType.Text
  26.                     ' we are going to use parameters in the SQL statement instead of trying to construct a string...
  27.                     ' NOTE the parameters here @REFNO,@QTY,@BOOKTITLE,@YEAR,@AUTHOR,@PRICE,@PUBLISHER...
  28.                     .CommandText = "INSERT INTO MECHATRONICS (`REFNO`, `QTY`, `BOOKTITLE`, `YEAR`, `AUTHOR`, `PRICE`, `PUBLISHER`) values (@REFNO,@QTY,@BOOKTITLE,@YEAR,@AUTHOR,@PRICE,@PUBLISHER)"
  29.  
  30.                     ' this is were we set the values for each parameter (in the above SQL)
  31.                     .CommandType = CommandType.Text ' You missed this line
  32.                     .Parameters.AddWithValue("@xid", txtRef.Text)
  33.                     .Parameters.AddWithValue("@m_id", txtQty.Text)
  34.                     .Parameters.AddWithValue("@imodel", txtYear.Text)
  35.                     .Parameters.AddWithValue("@icolor", txtAuthor.Text)
  36.                     .Parameters.AddWithValue("@ch_id", txtPrice.Text)
  37.                     .Parameters.AddWithValue("@pt_num", txtBook.Text)
  38.                     .Parameters.AddWithValue("@icode", txtPub.Text)
  39.                     ' Each parameter is substituted with the value from the texboxes when it is sent to the Database (ExecuteNonQuery)
  40.                 End With
  41.  
  42.                 cmdinfo.Connection = con
  43.                 cmdinfo.Connection.Open()
  44.                 cmdinfo.ExecuteNonQuery()
  45.  
  46.                 con.Close()
  47.                 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  48.                 MsgBox("new data has been save!", MsgBoxStyle.Information)
  49.                 txtRef.Text = ""
  50.                 Me.Close()
  51.  
  52.             Else
  53.                 MsgBox("information has save")
  54.                 txtRef.Text = ""
  55.                 txtQty.Text = ""
  56.                 txtBook.Text = ""
  57.                 txtAuthor.Text = ""
  58.                 txtPrice.Text = ""
  59.                 txtPub.Text = ""
  60.  
  61.             End If
  62.         End If ' <- added end if statement
  63.                ' ^^^^^^^^NEW COMMENT^^^^^^^^
  64.  
  65.     End Sub
  66. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement