[size=2][/size][size=2][color=#0000ff]Private[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub[/color][/size][size=2] ButtonAddEvent_Click([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2] ButtonAddEvent.Click[/size]
[size=2][color=#008000]'check that all fields are filled, easier than doing it on the database[/color][/size]
[size=2][color=#0000ff]If[/color][/size][size=2] TextBoxTitle.Text = "" [/size][size=2][color=#0000ff]And[/color][/size][size=2] [/size][size=2][color=#0000ff]Me[/color][/size][size=2].TextBoxDetails.Text = "" [/size][size=2][color=#0000ff]And[/color][/size][size=2] [/size][size=2][color=#0000ff]Me[/color][/size][size=2].TextBoxDate.Text = "" [/size][size=2][color=#0000ff]Then[/color][/size]
[size=2]StatusBar1.Text = "You must fill all fields"[/size]
[size=2][color=#0000ff]Else[/color][/size]
[size=2][color=#0000ff]Dim[/color][/size][size=2] sql [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]String[/color][/size]
[size=2]sql = "INSERT INTO events(Details, Title, [Date])VALUES(@Details, @Title, @Date)"[/size]
[size=2][color=#0000ff]Dim[/color][/size][size=2] SQLreturn [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]Integer[/color][/size]
[size=2]OleDbCommand1.CommandText = sql[/size]
[size=2][color=#0000ff]Try[/color][/size]
[size=2]OleDbConnection1.Open()[/size]
[size=2]OleDbCommand1.Parameters.Add("@Details", TextBoxDetails.Text)[/size]
[size=2]OleDbCommand1.Parameters.Add("@Date", TextBoxDate.Text)[/size]
[size=2]OleDbCommand1.Parameters.Add("@Title", TextBoxTitle.Text)[/size]
[size=2]SQLreturn = OleDbCommand1.ExecuteNonQuery[/size]
[size=2][color=#0000ff]Catch[/color][/size][size=2] ex [/size][size=2][color=#0000ff]As[/color][/size][size=2] Exception[/size]
[size=2]StatusBar1.Text = ex.Message[/size]
[size=2][color=#0000ff]Finally[/color][/size]
[size=2]OleDbConnection1.Close()[/size]
[size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]Try[/color][/size]
[size=2][color=#0000ff]If[/color][/size][size=2] SQLreturn <> 1 [/size][size=2][color=#0000ff]Then
[/color][/size][size=2]StatusBar1.Text = "Insert failed"
[/size][size=2][color=#0000ff]Else[/color][/size]
[size=2]StatusBar1.Text = "INSERT completed"[/size]
[size=2]TextBoxDetails.Text = ""[/size]
[size=2]TextBoxDate.Text = ""[/size]
[size=2]TextBoxTitle.Text = ""
[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If[/color][/size]
[size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If[/color][/size]
[size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub
[/color][/size]