borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Dataset related question?)Next Topic (Typed Dataset) New Topic New Poll Post Reply
AndreaVB Forum : VB.Net : vb.net query
Poster Message
sanjitsil
Level: Guest


icon vb.net query

I am learning VB.NET, trying to insert record in database using oledbCommand.
I am getting an error  Which is typed below  during compiling the programe. I am sending the source code as an attachment.
Please rectify the error and send me.

ERROR MESSAGE: An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll

____________________________
Attached:
WindowsApplication5.zip 36 KB (Downloads: 5)

30-12-2003 at 12:01 PM
| Quote Reply
fabulous
Level: VB Guru


Registered: 03-08-2002
Posts: 439
icon Re: vb.net query

Hi. I have good news and I have bad news. the good news is that I managed to make your code work. But the bad news is that I lost your connection string when I changed it to reflect where the database was on my system so you will have to change it back.

The problem seems to me as if the connection string needed the parameters/arguments such as Data Source to be enclosed in quotes. as in

ConnectionString = "Data Source=""...."";Provider=""Mic...."""


Happy coding.

Let me know if that was helpful.

____________________________
My boss is a Jewish Carpenter (Jesus Christ)


Brain Bench Certified VB.NET Developer

____________________________
Attached:
WindowsApplication5.zip 42 KB (Downloads: 1)

30-12-2003 at 07:22 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
fabulous
Level: VB Guru


Registered: 03-08-2002
Posts: 439
icon Re: vb.net query

One other thing. When I opened your solution, visual studio told me that I have to convert it to the version I use. I use a later version than yours - Visual Studio .NET 2003 Enterprise Architect. It mentioned that it might not open with earlier versions, so you might have to use notepad and copy and paste (plug and play) the code back into you project. happy coding.

____________________________
My boss is a Jewish Carpenter (Jesus Christ)


Brain Bench Certified VB.NET Developer

31-12-2003 at 04:25 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
MacD
Level: Big Cheese

Registered: 06-01-2004
Posts: 19
icon 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,

07-01-2004 at 07:00 AM
View Profile Send Email to User Show All Posts | Quote Reply
fabulous
Level: VB Guru


Registered: 03-08-2002
Posts: 439
icon Re: vb.net query

Good observation MacD. I overlooked that when I was posting my reply. I noticed that it kept giving me exceptions when I was inserting records so I caught it using a Try..Catch block. I did not set the MaxLength property, but continued to worry about the connection.

____________________________
My boss is a Jewish Carpenter (Jesus Christ)


Brain Bench Certified VB.NET Developer

07-01-2004 at 11:09 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : VB.Net : vb.net query
Previous Topic (Dataset related question?)Next Topic (Typed Dataset) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder