vs2008连接sql2000连不上也没报错就直接跳回代码部分,很急!希望各位能帮忙看看!谢谢!!!
Imports System.Data.SqlClientPublic Class rukulr
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
clear()
End Sub
Private Sub add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles add.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "" Or TextBox7.Text = "" Then
MsgBox("不能为空")
Else
SingleYanZheng()
End If
End Sub
Sub SingleYanZheng()
Dim str As String
str = "Data Source=localhost;Initial Catalog=shop;Integrated Security=True"
Dim con As New SqlConnection(str)
con.Open()
Dim sql As String = "select*from rkb where 商品名称='" & TextBox1.Text.ToString().Trim() & "'and 商品编号='" & TextBox2.Text.ToString().Trim() & "'and 入库价格='" & TextBox3.Text.ToString().Trim() & "'and 商品厂家='" & TextBox4.Text.ToString().Trim() & "and 经办人='" & TextBox5.Text.ToString().Trim() & "''and 入库数量='" & TextBox6.Text.ToString().Trim() & "and 入库日期='" & TextBox7.Text.ToString().Trim() & "''"
Dim cmd As New SqlCommand(sql, con)
Dim reader As SqlDataReader
reader = cmd.ExecuteReader
If reader.Read() Then
MsgBox("已经添加过这个商品了")
clear()
Else
addrukub()
MsgBox("success")
clear()
End If
End Sub
Sub addrukub()
Dim str As String
str = "Data Source=localhost;Initial Catalog=shop;Integrated Security=True"
Dim con As New SqlConnection(str)
con.Open()
Dim sql As String = "select*from rkb where 商品名称='" & TextBox1.Text.ToString().Trim() & "'and 商品编号='" & TextBox2.Text.ToString().Trim() & "'and 入库价格='" & TextBox3.Text.ToString().Trim() & "'and 商品厂家='" & TextBox4.Text.ToString().Trim() & "and 经办人='" & TextBox5.Text.ToString().Trim() & "''and 入库数量='" & TextBox6.Text.ToString().Trim() & "and 入库日期='" & TextBox7.Text.ToString().Trim() & "''"
Dim cmd As New SqlCommand(sql, con)
Try
cmd.ExecuteNonQuery()
Catch ex As Exception
End Try
Console.WriteLine("Record Added")
End Sub
Sub clear()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.Close()
End Sub
End Class 用ADODC连接数据库生成连接字符串.
字段名最好不要用中文, SQL语句书写注意风格, 虽说不介意关键字大小写之类的, 但是出错调试起来很糟糕.
字段显示的中文名可以放到SQL字段备注中, 下面是如何获得SQL备注信息的代码:
http://blog.csdn.net/wallescai/article/details/6037836 断点debug看看吧 用try catch
设个断点看看
补充:VB , 数据库(包含打印,安装,报表)