使用vb.net将插入数据连接到数据库
问题描述:
Hai,我在使用sql命令时遇到问题.这是我的代码,我试图在数据库中添加数据.对于您的信息,我正在使用sql server2005.请帮助我更正我的编码.
Hai, i have a probleam with sql command .Here is my code which iam 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
答
dealer
表中有几列?如果您有多个,则此查询应保存需要插入表中的所有值(除非所有其他列均设置了默认值).
How many columns do you have in the dealer
table? If you have more than one, then this query should hold all the values that need to be inserted into the table (unless all the other columns have defaults set).