Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Tambah_Maklumat
- Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- If txtRef.Text = "" Or txtQty.Text = "" Or txtYear.Text = "" Or txtAuthor.Text = "" Or txtPrice.Text Or
- txtPub.Text = "" Then
- MsgBox("please fill in the blank", MsgBoxStyle.Information) ' <- move this line to a new line
- ' ^^^^^^^^^^^^^NEW COMMENT^^^^^^^^^^^^
- 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"
- If MessageBox.Show("confrim add?", "Add books", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- Dim con As New OleDb.OleDbConnection
- Dim cmdinfo As New OleDb.OleDbCommand
- Dim dbProvider As String
- Dim dbSource As String
- dbProvider = "Provider=Microsoft.Jet.OLEDB.4.0; "
- dbSource = "data source=" & AppDomain.CurrentDomain.BaseDirectory & "Database2.mdb"
- con.ConnectionString = dbProvider & dbSource
- With cmdinfo ' this simply saves us having to type in cmdinfo every time
- .CommandType = CommandType.Text
- ' we are going to use parameters in the SQL statement instead of trying to construct a string...
- ' NOTE the parameters here @REFNO,@QTY,@BOOKTITLE,@YEAR,@AUTHOR,@PRICE,@PUBLISHER...
- .CommandText = "INSERT INTO MECHATRONICS (`REFNO`, `QTY`, `BOOKTITLE`, `YEAR`, `AUTHOR`, `PRICE`, `PUBLISHER`) values (@REFNO,@QTY,@BOOKTITLE,@YEAR,@AUTHOR,@PRICE,@PUBLISHER)"
- ' this is were we set the values for each parameter (in the above SQL)
- .CommandType = CommandType.Text ' You missed this line
- .Parameters.AddWithValue("@xid", txtRef.Text)
- .Parameters.AddWithValue("@m_id", txtQty.Text)
- .Parameters.AddWithValue("@imodel", txtYear.Text)
- .Parameters.AddWithValue("@icolor", txtAuthor.Text)
- .Parameters.AddWithValue("@ch_id", txtPrice.Text)
- .Parameters.AddWithValue("@pt_num", txtBook.Text)
- .Parameters.AddWithValue("@icode", txtPub.Text)
- ' Each parameter is substituted with the value from the texboxes when it is sent to the Database (ExecuteNonQuery)
- End With
- cmdinfo.Connection = con
- cmdinfo.Connection.Open()
- cmdinfo.ExecuteNonQuery()
- con.Close()
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- MsgBox("new data has been save!", MsgBoxStyle.Information)
- txtRef.Text = ""
- Me.Close()
- Else
- MsgBox("information has save")
- txtRef.Text = ""
- txtQty.Text = ""
- txtBook.Text = ""
- txtAuthor.Text = ""
- txtPrice.Text = ""
- txtPub.Text = ""
- End If
- End If ' <- added end if statement
- ' ^^^^^^^^NEW COMMENT^^^^^^^^
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement