使用vb.net将插入数据连接到数据库 [英] Connect insert data into database using vb.net

查看:124
本文介绍了使用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).


这篇关于使用vb.net将插入数据连接到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆