新手问题,大虾请帮忙!
wx_zl 2007-01-22 10:13:34 做一个下拉表单,具有添加功能.
首先从oracle抽取数据,放入定义的数据集ds,将其中的WIP_ENTITY_NAME显示在下拉菜单中,选中某一个,添按加按钮(Button4),将数据添加进sql数据库JOB_SPILIT,如果库中已经有数据则不添加.
Imports System.Windows.Forms
Imports DataBase
Public Class JobSplitForm
Private ds, ds1 As DataSet
Private myOracleData As New OracleData()
Private mySqlData As New SqlData()
Private Sub GetDataLoad()
ds = myOracleData.JOB_Select()
If ds.Tables(0).Rows.Count > 0 Then
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
JobComboBox.Items.Add(ds.Tables(0).Rows(i)("WIP_ENTITY_NAME").ToString().Trim())
Next
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If JobComboBox.Text = "" Then
MessageBox.Show("工单单号为空!", "提示")
Else
ds1 = mySqlData.JOBSPLIT_SELECT(JobComboBox.SelectedItem.ToString().Trim())
If ds1.Tables(0).Rows.Count = 0 Then
Dim i, j As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
If ds.Tables(0).Rows(i)("WIP_ENTITY_ID").ToString() = JobComboBox.SelectedItem.ToString() Then
j = i
If mySqlData.JOBSPLIT_INSERT(ds.Tables(0).Rows(j)("WIP_ENTITY_NAME").ToString(), ds.Tables(0).Rows(j)("WIP_ENTITY_ID").ToString(), ds.Tables(0).Rows(j)("PRIMARY_ITEM_ID").ToString()) = True Then
MessageBox.Show("添加成功!", "提示")
Else
MessageBox.Show("该数据已经存在,插入失败!", "提示")
End If
End If
Next
End If
End If
End Sub
Private Sub JobSplitForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GetDataLoad()
End Sub
End Class
sql引用:
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, ByVal str2 As String, ByVal str3 As String) As Boolean
dsCommand.InsertCommand = New SqlCommand("INSERT INTO JOB_SPLIT(WIP_ENTITY_ID,WIP_ENTITY_NAME,PRIMARY_ITEM_ID) VALUES('" + str1 + "','" + str2 + "','" + str3 + "')", con)
Try
dsCommand.InsertCommand.Connection.Open()
dsCommand.InsertCommand.ExecuteNonQuery()
JOBSPLIT_INSERT = True
Catch
JOBSPLIT_INSERT = False
End Try
dsCommand.InsertCommand.Connection.Close()
End Function
实在找不出,郁闷老半天了,具体思路如上,请大家帮帮忙,感激万分!