Question probleam with sql insert data

Iswan

Member
Joined
Aug 9, 2011
Messages
8
Programming Experience
Beginner
Hai, i have a probleam with sql command .Here is my code which i am try to add data in database. For your info i am using sql server 2005.. Please help me to correct my coding.

Imports System.Data.SqlClient

Public Class page

Private Sub btnaddsuplier_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddsuplier.Click

Dim connection As New SqlConnection
connection.ConnectionString = " Data Source=Danawa;Initial Catalog=Store;Integrated Security=True"
Dim cmd1 As SqlCommand
dim ra as integer

Try
connection.Open()
cmd1 = New SqlCommand("INSERT INTO dealer (dname) VALUES ('" & txtadddeletesupplier.Text & "')", connection)
ra = cmd.ExecuteNonQuery()
MsgBox("Category Added!!", MsgBoxStyle.Information, "Record Added = " & ra)
Catch ex As Exception
MsgBox("Category Failed to add!!", MsgBoxStyle.Critical)
End Try

end sub
end class
 
First things first, you are just ignoring the exception and displaying a generic error message. Actually look at the exception and it will tell you what the issue is.

Apart from that, follow the Blog link in my signature and check out my post on ADO.NET parameters to learn how to properly insert values into SQL code.
 
Back
Top