新手:连接数据库的问题
Private ds As DataSet
ds.Clear()
ds = mySqlData.JOBSPLIT_SELECT(JobComboBox.Text.ToString())
If ds.Tables(0).Rows.Count = 0 Then
If mySqlData.JOBSPLIT_INSERT(JobComboBox.Text.ToString()) = True Then
MessageBox.Show( "添加成功 ", "提示 ")
Else
MessageBox.Show( "数据已经存在,插入失败 ", "提示 ")
End If
End If
定义:
Public Function JOBSPLIT_SELECT(ByVal str1 As String) As DataSet
Dim data As New DataSet()
Dim strSql As String
strSql = "SELECT * FROM JOB_SPLIT WHERE WIP_ENTITY_NAME= ' " + str1 + " ' "
dsCommand.SelectCommand = New SqlCommand(strSql, con)
dsCommand.Fill(data)
JOBSPLIT_SELECT = data
End Function
Public Function JOBSPLIT_INSERT(ByVal str1 As String) As Boolean
dsCommand.InsertCommand = New SqlCommand( "INSERT INTO WIP_ENTITY_NAME VALUES( " + str1 + ") FROM JOB_SPLIT ", con)
Try
dsCommand.InsertCommand.Connection.Open()
dsCommand.InsertCommand.ExecuteNonQuery()
JOBSPLIT_INSERT = True
Catch
JOBSPLIT_INSERT = False
End Try
dsCommand.InsertCommand.Connection.Close()
End Function
重要程序如上,说下思路,jobcombobox里选择一个数据,然后连接数据库,看数据库里有无这个数据的存在,如已经存在,则不插入,不存在,则插入.
问题是这样的:运行没有出现错误提示,可以运行,但是只显示 "数据已经存在,插入失败 ",前提条件是JOB_SPLIT还是个空表.
VS2005,VB
刚接触,还望大虾多多指教,谢谢!
[解决办法]
接分