Hello guys,
I'm now wirting a program that is expected to excute a conditional SQL query.
following is part of my code:
I'm wondering if this code can run as expected. In other words, whether the previous data in datatable can be updated by the data got from the next "GetData" statement. And whether this condition goes the same in datagridview.
Thank you very much!!
I'm now wirting a program that is expected to excute a conditional SQL query.
following is part of my code:
VB.NET:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] method()[/SIZE]
[SIZE=2][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] dt [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataTable = GetData([/SIZE][SIZE=2][COLOR=#800000]"[SIZE=2][COLOR=#800000]
select lotid from actl where eqpid='S103SIG' and lotid not in (select lotid from rpt_del_lot)
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#800000]"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Not[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2]dt.Rows(r).Item([/SIZE][SIZE=2][COLOR=#800000]"lotid"[/COLOR][/SIZE][SIZE=2])[/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Is[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Nothing[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2]GetData([/SIZE][SIZE=2][COLOR=#800000]"SQL goes on here[/COLOR][/SIZE][SIZE=2][COLOR=#800000]"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]else [/SIZE]
[SIZE=2]GetData([SIZE=2][COLOR=#800000]"SQL goes on here[/COLOR][/SIZE][SIZE=2][COLOR=#800000]"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][/COLOR][/SIZE][/SIZE][/SIZE]
VB.NET:
[SIZE=2][COLOR=#0000ff]
Public[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] GetData([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] selectCommand [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataTable
[/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2][/SIZE][COLOR=#008000][/COLOR][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] connectionString [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = _
[/SIZE][SIZE=2][COLOR=#800000]" Data Source=singdb;User ID=mfg_rpt;Password=sentosa;Unicode=True;"
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]' Create a new data adapter based on the specified query.
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].dataAdapter = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OracleDataAdapter(selectCommand, connectionString)
[/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] commandBuilder [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OracleCommandBuilder([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].dataAdapter)
[/SIZE][SIZE=2][COLOR=#008000]' Populate a new data table and bind it to the BindingSource.
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] dt [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataTable()
dt.Locale = System.Globalization.CultureInfo.InvariantCulture
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].dataAdapter.Fill(dt)
[/SIZE][SIZE=2][COLOR=#0000ff]Return[/COLOR][/SIZE][SIZE=2] dt
[/SIZE][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] ex [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] OracleException
MessageBox.Show([/SIZE][SIZE=2][COLOR=#800000]"To run this example, replace the value of the "[/COLOR][/SIZE][SIZE=2] + _
[/SIZE][SIZE=2][COLOR=#800000]"connectionString variable with a connection string that is "[/COLOR][/SIZE][SIZE=2] + _
[/SIZE][SIZE=2][COLOR=#800000]"valid for your system."[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Function
[/COLOR][/SIZE]
Thank you very much!!