VB2008 利用SQL做的一个家电下乡资料管理系统,想不添加已存在的记录,不知如何实现
B2008 利用SQL做的一个家电下乡资料管理系统,想不添加已存在的记录,不知如何实现:程序如下所示:(红色的的部分不会做)请高手给指点指点
Imports System.Data.SqlClient
Imports System.Data
Public Class zllrform
Dim objconn As New SqlConnection("server=localhost;database=家电下乡资料;user id=sa;password=000159")
Dim objdataadapter As New SqlDataAdapter()
Dim objdataset As New DataSet()
Dim objcommand As SqlCommand = New SqlCommand
Dim addbut As Boolean = False
Dim a As Integer
Private Sub butSver_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butSave.Click
If ((jqxh.Text <> "") And (pmgg.Text <> "") And (bskh.Text <> "") And (cpbh.Text <> "") And (yhmc.Text <> "")) Then
addbut = False
objcommand.Connection = objconn
= "select * from 家电下乡资料 " & " where 标识卡号='bskh.Text'"
objconn.Open()
If 这里不知判断什么 Then
MessageBox.Show("此卡已录入,不能重复录入" & a, "添加提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
objconn.Close()
Else
objconn.Close()
= "insert into 家电下乡资料" & "(机器型号,品名规格,标识卡号,产品编号,用户名称,所属公司) " & "values(@机器型号,@品名规格,@标识卡号,@产品编号,@用户名称,@所属公司)"
objcommand.Parameters.AddWithValue("@机器型号", jqxh.Text)
objcommand.Parameters.AddWithValue("@品名规格", pmgg.Text)
objcommand.Parameters.AddWithValue("@标识卡号", bskh.Text)
objcommand.Parameters.AddWithValue("@产品编号", cpbh.Text)
objcommand.Parameters.AddWithValue("@用户名称", yhmc.Text)
objcommand.Parameters.AddWithValue("@所属公司", butssgs.Text)
objconn.Open()
objcommand.ExecuteNonQuery()
objconn.Close()
MessageBox.Show("资料录入保存成功", "保存成功", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
Me.jqxh.Text = ""
Me.pmgg.Text = ""
Me.bskh.Text = ""
Me.cpbh.Text = ""
Me.yhmc.Text = ""
Me.jqxh.Enabled = False
Me.pmgg.Enabled = False
Me.bskh.Enabled = False
Me.cpbh.Enabled = False
Me.yhmc.Enabled = False
Me.ButAdd.Enabled = True
Me.butSave.Enabled = False
Me.cpbh.Text = ""
End If
Else
MessageBox.Show("录入项不能为空,请填写完整", "添加提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
End If
End Sub
Private Sub butcll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butcll.Click
addbut = False
Me.jqxh.Text = ""
Me.pmgg.Text = ""
Me.bskh.Text = ""
Me.cpbh.Text = ""
Me.yhmc.Text = ""
Me.jqxh.Enabled = False
Me.pmgg.Enabled = False
Me.bskh.Enabled = False
Me.cpbh.Enabled = False
Me.yhmc.Enabled = False
Me.ButAdd.Enabled = True
Me.butSave.Enabled = False
Me.Butcll.Enabled = False
End Sub
Private Sub ButAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButAdd.Click
addbut = True
Me.bskh.Text = ""
Me.cpbh.Text = ""
Me.yhmc.Text = ""
Me.jqxh.Enabled = True
Me.pmgg.Enabled = True
Me.bskh.Enabled = True
Me.cpbh.Enabled = True
Me.yhmc.Enabled = True
Me.ButAdd.Enabled = False
Me.butSave.Enabled = True
Me.Butcll.Enabled = True
End Sub
Private Sub Butclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butclose.Click
addbut = False
Me.jqxh.Text = ""
Me.pmgg.Text = ""
Me.bskh.Text = ""
Me.cpbh.Text = ""
Me.yhmc.Text = ""
Me.jqxh.Enabled = True
Me.pmgg.Enabled = True
Me.bskh.Enabled = True
Me.cpbh.Enabled = True
Me.yhmc.Enabled = True
Me.ButAdd.Enabled = False
Me.butSave.Enabled = True
Me.Close()
End Sub
Private Sub bskh_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bskh.TextChanged
End Sub
Private Sub zllrform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: 这行代码将数据加载到表“家电下乡资料DataSet1.公司名称”中。您可以根据需要移动或移除它。
Me.公司名称TableAdapter.Fill(Me.家电下乡资料DataSet1.公司名称)
'TODO: 这行代码将数据加载到表“家电下乡资料DataSet1.品名规格分表”中。您可以根据需要移动或移除它。
Me.品名规格分表TableAdapter.Fill(Me.家电下乡资料DataSet1.品名规格分表)
'TODO: 这行代码将数据加载到表“家电下乡资料DataSet1.机器型号分表”中。您可以根据需要移动或移除它。
Me.机器型号分表TableAdapter.Fill(Me.家电下乡资料DataSet1.机器型号分表)
'TODO: 这行代码将数据加载到表“家电下乡资料DataSet1.家电下乡资料”中。您可以根据需要移动或移除它。
End Sub
Private Sub 所属公司Label_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
End Class
[ 本帖最后由 卓越电脑 于 2010-8-16 20:32 编辑 ]