Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I trying to insert record in sql server table Record insert but not any
error record not be sown in table
check my code

What I have tried:

Dim sqlConnection As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Softlinks.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
        Dim cmd As New System.Data.SqlClient.SqlCommand
        cmd.CommandType = System.Data.CommandType.Text
        cmd.CommandText = "INSERT into Productitem (Productcode,Productname,Productprice)  values (12345,'Keyboard',1245)"

        cmd.Connection = sqlConnection

        sqlConnection.Open()
        cmd.ExecuteNonQuery()
        sqlConnection.Close()
Posted
Updated 18-Sep-16 9:32am
v2
Comments
Karthik_Mahalingam 18-Sep-16 5:48am    
getting any error? if so,
what is the error message?

Since you say that no error code is generated I take it that the error succeeds. However you should double check that with the debugger.

One potential reason for not seeing the newly inserted data is that if the database file is included in your project, it will be copied to the output folder each time you compile the application thus overwriting all previous modifications.

To ensure that this does not happen, try moving the database file to a static folder outside your output path, for example to a directory like C:\TEMP\TESTDATA and change the connection string to point to that location.
VB.NET
Dim sqlConnection As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\TEMP\TESTDATA\Softlinks.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
 
Share this answer
 
 
Share this 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