MacD Level: Big Cheese
 Registered: 06-01-2004 Posts: 19
|
Re: vb.net query
Good news for you.
The problem i have found out is that the size of the field called Empcode is 5 and if someone enters anything that is more than 5 characters long the system will fail to handle it (i.e from the database end). So set the MaxLength Property of TEXTBOX1 control to any number that is 5 or less so as for it to be compatible with the one specified in your database.
I urge you also to use the TRY CATCH block facility so as for you to be able to see what exactly the error is.
So just copy and paste and overwrite the button code with the one that is below into your Form1.vb class and PLEASE CHECK IF THE DATA SOURCE path i have specified IS CORRECT
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cmd As String
Dim myCommand As New OleDbCommand
cmd = "Insert Into Emp(ECode,EName) Values('" & TextBox1.Text.ToString & "','" & TextBox2.Text.ToString & "')"
con.ConnectionString= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Documents and Settings\Joydip\My Documents\Visual Studio Projects\WindowsApplication5\Test100.mdb"
con.Open()
myCommand.Connection = con
myCommand.CommandType = CommandType.Text
myCommand.CommandText = cmd
Try
myCommand.ExecuteNonQuery()
MsgBox("Record Added")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
con.Close()
End Sub
Have a great day papa.
Regards,
|