Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
VB
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnsave.Click
        Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        Try
            'con.ConnectionString = "Data Source=E550;Initial Catalog=DeviceDB;Integrated Security=True"

            con.Open()
            cmd.Connection = con
            cmd.CommandText = "INSERT INTO TBL_APPLICATION_COD VALUES('" & txtapcode.Text & "','" & txtapdes.Text & "')"
            cmd.ExecuteNonQuery()

        Catch ex As Exception
            'MsgBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records")
            MsgBox("Error " & ex.Message)
        Finally
            con.Close()
        End Try
    End Sub
Posted
Comments
Zoltán Zörgő 2-Jun-13 2:51am    
Of course not. And your question is....?

1 solution

The error is due to the line, which you have commented out...
VB
'con.ConnectionString = "Data Source=E550;Initial Catalog=DeviceDB;Integrated Security=True"

You should initialize the ConnectionString property of SqlConnection Class[^] before using its instance (in your code that is con).

So, don't comment this line and try. Make sure the ConnectionString is correct.

Else follow - http://connectionstrings.com/[^] to find the correct and appropriate ConnectionString for your application.
 
Share this answer
 
Comments
akhil.krish 2-Jun-13 3:26am    
thanq...
Most Welcme. My Pleasure.
Thanks for accepting the answer. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900