So my code is going through the various components and creates bundles using the BuildKnittingRecords sub for the various components. My code works well when it creates the bundles for the Case "Sleeve", "Front", "Body", "Back" but when it gets to Case "Collar22-32" it gets stuck in the do until loop and as a result will keep on adding to PnlsToProduce(until it crashes cos the number is too big) instead of only running through the do until loop when it finds that component
Private Sub knittingdetailsheaderdataset()
bundlenum = 1
Dim SQL As String
Dim Adapter As New OleDbDataAdapter
Dim dt As New DataTable
Using con As New OleDbConnection(cnString)
Dim cmd As New OleDbCommand()
SQL = "Select bla bla
FROM bla bla
INNER Join bla bla"
(it's a very long sql statement, and not relevent to my issue)
cmd.Connection = con
cmd.CommandText = SQL
Adapter.SelectCommand = cmd
Adapter.Fill(dt)
For dr As Integer = 0 To dt.Rows.Count - 1
componentName = dt(dr)(6)
knittOrderID = dt(dr)(4)
componentID = dt(dr)(3)
sizeID = dt(dr)(5)
qtyppnl = dt(dr)(10)
Select Case componentName
Case "Sleeve", "Front", "Body", "Back"
MxBndleSz = 36
PnlsToProduce = dt(dr)(11)
BuildKnittingRecords(MxBndleSz, componentID, sizeID, PnlsToProduce, qtyppnl, knittOrderID, bundlenum)
Case "Collar22-32"
MxBndleSz = 200
PnlsToProduce = 0
Do Until componentName <> "Collar22-32" Or dr = dt.Rows.Count - 1
PnlsToProduce += dt(dr)(11)
Loop
Select Case PnlsToProduce
Case 50 To 100
PnlsToProduce = PnlsToProduce + 1
Case 101 To 250
PnlsToProduce = PnlsToProduce + 2
Case Is > 250
PnlsToProduce = PnlsToProduce + 3
End Select
BuildKnittingRecords(MxBndleSz, componentID, sizeID, PnlsToProduce, qtyppnl, knittOrderID, bundlenum)
End Select
Next
End Using
End Sub
Hence my question is, why is it doing this and how do I solve it?
This is my code for the BuildknittingRecord() sub, not sure if it's relevant in solving my issue:
Private Sub BuildKnittingRecords(ByRef MaxBundleSz As Integer, ByRef compID As Integer, ByRef sizeID As Integer, ByRef PnlsToproduce As Integer, ByRef QtyPerPanel As Integer, ByRef KnittingOrderID As Integer, ByRef bundlenum As Integer)
pnls2prod = PnlsToproduce
Dim cmdstring As String
Do Until pnls2prod < 10
If bundlenum < 10 Then
bundleNo = txtbatchno.Text & "-K0" & bundlenum
Else
bundleNo = txtbatchno.Text & "-K" & bundlenum
End If
bundlenum += 1
If pnls2prod <= MaxBundleSz Then
PanelsToMake = pnls2prod
cmdstring = " INSERT INTO [KN - KnittingDetailsHeader] (BatchNo, BundleNo, ComponentID, SizeID, PanelsToMake, QtyPerPanel, KnittingOrderID) VALUES('" & txtbatchno.Text & "', '" & bundleNo & "', " & compID & ", " & sizeID & ", " & PanelsToMake & ", " & QtyPerPanel & ", " & KnittingOrderID & ");"
Using con As New OleDbConnection(cnString)
Dim cmd As New OleDbCommand(cmdstring)
cmd.CommandType = CommandType.Text
cmd.Connection = con
cmd.Connection.Open()
cmd.ExecuteNonQuery()
End Using
Exit Do
Else
If pnls2prod < 10 Then
PanelsToMake = pnls2prod + MaxBundleSz
cmdstring = " INSERT INTO [KN - KnittingDetailsHeader] (BatchNo, BundleNo, ComponentID, SizeID, PanelsToMake, QtyPerPanel, KnittingOrderID) VALUES('" & txtbatchno.Text & "', '" & bundleNo & "', " & compID & ", " & sizeID & ", " & PanelsToMake & ", " & QtyPerPanel & ", " & KnittingOrderID & ");"
Using con As New OleDbConnection(cnString)
Dim cmd As New OleDbCommand(cmdstring)
cmd.CommandType = CommandType.Text
cmd.Connection = con
cmd.Connection.Open()
cmd.ExecuteNonQuery()
End Using
Exit Do
End If
PanelsToMake = MaxBundleSz
pnls2prod = pnls2prod - MaxBundleSz
cmdstring = " INSERT INTO [KN - KnittingDetailsHeader] (BatchNo, BundleNo, ComponentID, SizeID, PanelsToMake, QtyPerPanel, KnittingOrderID) VALUES('" & txtbatchno.Text & "', '" & bundleNo & "', " & compID & ", " & sizeID & ", " & PanelsToMake & ", " & QtyPerPanel & ", " & KnittingOrderID & ");"
Using con As New OleDbConnection(cnString)
Dim cmd As New OleDbCommand(cmdstring)
cmd.CommandType = CommandType.Text
cmd.Connection = con
cmd.Connection.Open()
cmd.ExecuteNonQuery()
End Using
End If
Loop
End Sub
Related
I have the following VB.net code that updates the row from Boundedfields using the identifying the cell number.
Protected Sub grvPos_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles grvPos.RowUpdating
Dim cs As String
Dim con As iDB2Connection
Dim sql As String
Dim cmd As iDB2Command
Dim valDate As Integer
Dim portCode As String
Dim secCode As String
Dim valType As String
Dim portName As String
Dim ISINno As String
Dim secName As String
Dim secCcyAbbr As String
Dim trxBccy As Decimal
Dim quantity As Integer
Dim mktPrice As Integer
Dim avgCost As Integer
Dim avgBvalSc As Integer
Dim avgBvalBc As Integer
Dim intAmtSc As Integer
Dim intAmtBc As Integer
Dim gr As GridViewRow
gr = grvPos.Rows(e.RowIndex)
valDate = grvPos.DataKeys(gr.RowIndex).Values("VALN_DATE")
portCode = grvPos.DataKeys(gr.RowIndex).Values("PORT_CODE").ToString()
secCode = grvPos.DataKeys(gr.RowIndex).Values("SEC_CODE").ToString()
valType = grvPos.Rows(gr.RowIndex).Cells(2).ToString()
portName = grvPos.Rows(gr.RowIndex).Cells(4).ToString()
ISINno = grvPos.Rows(gr.RowIndex).Cells(6).ToString()
secName = grvPos.Rows(gr.RowIndex).Cells(7).ToString()
secCcyAbbr = grvPos.Rows(gr.RowIndex).Cells(8).ToString()
trxBccy = grvPos.Rows(gr.RowIndex).Cells(9).ToString()
quantity = CInt(grvPos.Rows(gr.RowIndex).Cells(10).ToString())
mktPrice = CInt(grvPos.Rows(gr.RowIndex).Cells(11).ToString())
avgCost = CInt(grvPos.Rows(gr.RowIndex).Cells(14).ToString())
avgBvalSc = CInt(grvPos.Rows(gr.RowIndex).Cells(15).ToString())
avgBvalBc = CInt(grvPos.Rows(gr.RowIndex).Cells(16).ToString())
intAmtSc = CInt(grvPos.Rows(gr.RowIndex).Cells(17).ToString())
intAmtBc = CInt(grvPos.Rows(gr.RowIndex).Cells(18).ToString())
cs = ConfigurationManager.ConnectionStrings("ConnectionStringDB2").ConnectionString
con = New iDB2Connection(cs)
sql = "MERGE INTO GICPFDTA.OPTR_POS_FIX O " &
"USING OLYFPRO.FDBVAL F ON O.SEC_CODE = F.VLVALR " &
"AND (O.VALN_DATE = #VALN_DATE) " &
"AND (O.PORT_CODE = #PORT_CODE) " &
"AND (O.SEC_CODE = #SEC_CODE) " &
"WHEN MATCHED THEN UPDATE SET " &
"O.VAL_TYPE = #VAL_TYPE " &
",O.PORT_SNAME = #PORT_SNAME " &
",O.ISIN_NO = #ISIN_NO " &
",O.SEC_SNAME = #SEC_SNAME " &
",O.SEC_CCY_ABBR = #SEC_CCY_ABBR " &
",O.TRX_BCCY_EX_RATE = #TRX_BCCY_EX_RATE " &
",O.QUANTITY = #QUANTITY " &
",O.MKT_PRICE = #MKT_PRICE " &
",O.AVG_COST = #AVG_COST " &
",O.AVG_BVAL_SC = #AVG_BVAL_SC " &
",O.AVG_BVAL_BC = #AVG_BVAL_BC " &
",O.INT_AMT_SC = #INT_AMT_SC " &
",O.INT_AMT_BC = #INT_AMT_BC " &
",O.MVAL_AMT_SC = ROUND(#QUANTITY * #MKT_PRICE / (" &
"CASE " &
"WHEN F.VLGTI = 100 " &
"THEN 100 " &
"ELSE 1 " &
"END" &
"), 3) " &
",O.MVAL_AMT_BC = ROUND(#QUANTITY * #MKT_PRICE / (" &
"CASE " &
"WHEN F.VLGTI = 100 " &
"THEN 100 " &
"ELSE 1 " &
"END" &
") / #TRX_BCCY_EX_RATE, 3)"
cmd = New iDB2Command(sql, con)
cmd.Parameters.AddWithValue("#VALN_DATE", valDate)
cmd.Parameters.AddWithValue("#PORT_CODE", portCode)
cmd.Parameters.AddWithValue("#SEC_CODE", secCode)
cmd.Parameters.AddWithValue("#VAL_TYPE", valType)
cmd.Parameters.AddWithValue("#PORT_SNAME", portName)
cmd.Parameters.AddWithValue("#ISIN_NO", ISINno)
cmd.Parameters.AddWithValue("#SEC_SNAME", secName)
cmd.Parameters.AddWithValue("#SEC_CCY_ABBR", secCcyAbbr)
cmd.Parameters.AddWithValue("#TRX_BCCY_EX_RATE", trxBccy)
cmd.Parameters.AddWithValue("#TRX_BCCY_EX_RATE", trxBccy)
cmd.Parameters.AddWithValue("#QUANTITY", quantity)
cmd.Parameters.AddWithValue("#QUANTITY", quantity)
cmd.Parameters.AddWithValue("#QUANTITY", quantity)
cmd.Parameters.AddWithValue("#MKT_PRICE", mktPrice)
cmd.Parameters.AddWithValue("#MKT_PRICE", mktPrice)
cmd.Parameters.AddWithValue("#MKT_PRICE", mktPrice)
cmd.Parameters.AddWithValue("#AVG_COST", avgCost)
cmd.Parameters.AddWithValue("#AVG_BVAL_SC", avgBvalSc)
cmd.Parameters.AddWithValue("#AVG_BVAL_BC", avgBvalBc)
cmd.Parameters.AddWithValue("#INT_AMT_SC", intAmtSc)
cmd.Parameters.AddWithValue("#INT_AMT_BC", intAmtBc)
Try
lblError.Text = ""
Using con
con.Open()
cmd.ExecuteNonQuery()
gridLoad()
End Using
Catch ex As Exception
Throw
End Try
End Sub
The trxBccy variable is Numeric data type, but I specified it as Decimal, I also tried Integer data type.
When I try to update a row I get the following error:
Conversion from string "System.Web.UI.WebControls.DataCo" to type 'Decimal' is not valid.
I appreciate any help.
Thanks in advance
I was able to capture the values from the bounded fields using the below code.
Protected Sub grvPos_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles grvPos.RowUpdating
Dim cs As String
Dim con As iDB2Connection
Dim sql As String
Dim cmd As iDB2Command
Dim valDate As Integer
Dim portCode As String
Dim secCode As String
Dim valType As String
Dim portName As String
Dim ISINno As String
Dim secName As String
Dim secCcyAbbr As String
Dim trxBccy As Decimal
Dim quantity As Decimal
Dim mktPrice As Decimal
Dim avgCost As Decimal
Dim avgBvalSc As Decimal
Dim avgBvalBc As Decimal
Dim intAmtSc As Decimal
Dim intAmtBc As Decimal
Dim gr As GridViewRow
gr = grvPos.Rows(e.RowIndex)
valDate = grvPos.DataKeys(gr.RowIndex).Values("VALN_DATE")
portCode = grvPos.DataKeys(gr.RowIndex).Values("PORT_CODE").ToString()
secCode = grvPos.DataKeys(gr.RowIndex).Values("SEC_CODE").ToString()
valType = e.NewValues("VAL_TYPE").ToString()
portName = e.NewValues("PORT_SNAME").ToString()
ISINno = e.NewValues("ISIN_NO").ToString()
secName = e.NewValues("SEC_SNAME").ToString()
secCcyAbbr = e.NewValues("SEC_CCY_ABBR").ToString()
trxBccy = e.NewValues("TRX_BCCY_EX_RATE").ToString()
quantity = e.NewValues("QUANTITY").ToString()
mktPrice = e.NewValues("MKT_PRICE").ToString()
avgCost = e.NewValues("AVG_COST").ToString()
avgBvalSc = e.NewValues("AVG_BVAL_SC").ToString()
avgBvalBc = e.NewValues("AVG_BVAL_BC").ToString()
intAmtSc = e.NewValues("INT_AMT_SC").ToString()
intAmtBc = e.NewValues("INT_AMT_BC").ToString()
cs = ConfigurationManager.ConnectionStrings("ConnectionStringDB2").ConnectionString
con = New iDB2Connection(cs)
sql = "MERGE INTO GICPFDTA.OPTR_POS_FIX O " &
"USING OLYFPRO.FDBVAL F ON O.SEC_CODE = F.VLVALR " &
"AND (O.VALN_DATE = #VALN_DATE) " &
"AND (O.PORT_CODE = #PORT_CODE) " &
"AND (O.SEC_CODE = #SEC_CODE) " &
"WHEN MATCHED THEN UPDATE SET " &
"O.VAL_TYPE = #VAL_TYPE " &
",O.PORT_SNAME = #PORT_SNAME " &
",O.ISIN_NO = #ISIN_NO " &
",O.SEC_SNAME = #SEC_SNAME " &
",O.SEC_CCY_ABBR = #SEC_CCY_ABBR " &
",O.TRX_BCCY_EX_RATE = #TRX_BCCY_EX_RATE " &
",O.QUANTITY = #QUANTITY " &
",O.MKT_PRICE = #MKT_PRICE " &
",O.AVG_COST = #AVG_COST " &
",O.AVG_BVAL_SC = #AVG_BVAL_SC " &
",O.AVG_BVAL_BC = #AVG_BVAL_BC " &
",O.INT_AMT_SC = #INT_AMT_SC " &
",O.INT_AMT_BC = #INT_AMT_BC " &
",O.MVAL_AMT_SC = ROUND(#QUANTITY * #MKT_PRICE / (" &
"CASE " &
"WHEN F.VLGTI = 100 " &
"THEN 100 " &
"ELSE 1 " &
"END" &
"), 3) " &
",O.MVAL_AMT_BC = ROUND(#QUANTITY * #MKT_PRICE / (" &
"CASE " &
"WHEN F.VLGTI = 100 " &
"THEN 100 " &
"ELSE 1 " &
"END" &
") / #TRX_BCCY_EX_RATE, 3)"
cmd = New iDB2Command(sql, con)
cmd.Parameters.AddWithValue("#VALN_DATE", valDate)
cmd.Parameters.AddWithValue("#PORT_CODE", portCode)
cmd.Parameters.AddWithValue("#SEC_CODE", secCode)
cmd.Parameters.AddWithValue("#VAL_TYPE", valType)
cmd.Parameters.AddWithValue("#PORT_SNAME", portName)
cmd.Parameters.AddWithValue("#ISIN_NO", ISINno)
cmd.Parameters.AddWithValue("#SEC_SNAME", secName)
cmd.Parameters.AddWithValue("#SEC_CCY_ABBR", secCcyAbbr)
cmd.Parameters.AddWithValue("#TRX_BCCY_EX_RATE", trxBccy)
cmd.Parameters.AddWithValue("#TRX_BCCY_EX_RATE", trxBccy)
cmd.Parameters.AddWithValue("#QUANTITY", quantity)
cmd.Parameters.AddWithValue("#QUANTITY", quantity)
cmd.Parameters.AddWithValue("#QUANTITY", quantity)
cmd.Parameters.AddWithValue("#MKT_PRICE", mktPrice)
cmd.Parameters.AddWithValue("#MKT_PRICE", mktPrice)
cmd.Parameters.AddWithValue("#MKT_PRICE", mktPrice)
cmd.Parameters.AddWithValue("#AVG_COST", avgCost)
cmd.Parameters.AddWithValue("#AVG_BVAL_SC", avgBvalSc)
cmd.Parameters.AddWithValue("#AVG_BVAL_BC", avgBvalBc)
cmd.Parameters.AddWithValue("#INT_AMT_SC", intAmtSc)
cmd.Parameters.AddWithValue("#INT_AMT_BC", intAmtBc)
Try
lblError.Text = ""
Using con
con.Open()
cmd.ExecuteNonQuery()
grvPos.EditIndex = -1
gridLoad()
End Using
Catch ex As Exception
Throw
End Try
End Sub
I have two table which are FixedAssetMaster and ScanningData table. When click Update button, it automatically save data to both table. When i save data to ScanningTable, there is no problem. But when i want to save the data to FixedAssetMaster table, the error come out. Currently i set UNIT_NO as nvarchar. When i change it to int there is no problem. Here is my source code.
UNIT_NO data sample is 002
Saving to Scanning Data:
cmd = New SqlCommand
cmd.CommandText = "SELECT COUNT(*) FROM ScanningData WHERE ASSET_NUMBER=" & AssetTxt.Text & " AND LOC_DEPT=" & DeptCodeTxt.Text & " AND UNIT_NO='" & UnitNoTxt.Text & "';"
cmd.Connection = Conn
rdmysql = cmd.ExecuteReader
If rdmysql.Read = True Then
reccount = Val(rdmysql.GetInt32(0))
End If
cmd.Dispose()
rdmysql.Close()
If reccount = 0 Then
strsql = "INSERT INTO ScanningData"
strsql += "(ASSET_NUMBER,LOC_DEPT,DEPT_DESCRIPTION,MAJOR_CATEGORY,DATE_PLACED_IN_SERVICE,LOC_AREA,IT_TAG_NO,UNITS_ASSIGNED,DESCRIPTION,MYR_COST_BY_UNIT,COST_BY_UNIT,DEPRN_RESERVE_BY_UNIT,DATE_RETIRED,ASSET_KEY_SEGMENT3,UNIT_NO,SERIAL_NUMBER,NBV_BY_UNIT_USD,UPDATE_DATE,UPDATE_BY) VALUES "
strsql += "(#ID, #CODE, #DEPT, #CATEGORY, #SERVICEDATE, #AREA, #TAG, #UNIT, #DESCRIPTION, #MYRCOST, #USDCOST, #DEPR, #RETIREDDATE, #LocDesc, #UnitNo, #SN, #NBV, #UPDATEDATE, #NAME);"
cmd = New SqlCommand
cmd.Connection = Conn
cmd.Parameters.AddWithValue("#ID", AssetTxt.Text)
cmd.Parameters.AddWithValue("#CODE", DeptCodeTxt.Text)
cmd.Parameters.AddWithValue("#DEPT", DeptTxt.Text)
cmd.Parameters.AddWithValue("#CATEGORY", CategoryTxt.Text)
cmd.Parameters.AddWithValue("#SERVICEDATE", ServiceTxt.Text)
cmd.Parameters.AddWithValue("#AREA", LocTxt.Text)
cmd.Parameters.AddWithValue("#TAG", TagTxt.Text)
Dim unit As Integer = Integer.Parse(UnitTxt.Text)
cmd.Parameters.AddWithValue("#UNIT", unit)
cmd.Parameters.AddWithValue("#DESCRIPTION", DescTxt.Text)
Dim MYRCost As Decimal = Decimal.Parse(CostMYRTxt.Text)
cmd.Parameters.AddWithValue("#MYRCOST", MYRCost)
Dim USDCost As Decimal = Decimal.Parse(CostUSDTxt.Text)
cmd.Parameters.AddWithValue("#USDCOST", USDCost)
Dim Depr As Decimal = Decimal.Parse(DeprTxt.Text)
cmd.Parameters.AddWithValue("#DEPR", Depr)
cmd.Parameters.AddWithValue("#RETIREDDATE", RetiredDateTxt.Text)
cmd.Parameters.AddWithValue("#LocDesc", LocDescTxt.Text)
cmd.Parameters.AddWithValue("#UnitNo", UnitNoTxt.Text)
cmd.Parameters.AddWithValue("#SN", SNTxt.Text)
cmd.Parameters.AddWithValue("#NBV", NBVUSDTxt.Text)
cmd.Parameters.AddWithValue("#UPDATEDATE", ServerDate)
cmd.Parameters.AddWithValue("#NAME", UserIDLabel.Text)
cmd.CommandText = strsql
cmd.ExecuteNonQuery()
End If
saving to FixedAssetMaster:
cmd = New SqlCommand
'cmd.CommandText = "SELECT COUNT(*) FROM ScanningData WHERE ASSET_NUMBER=" & AssetTxt.Text & " AND LOC_DEPT=" & DeptCodeTxt.Text & " and UPDATE_DATE='" & NEWYEAR & "';"
cmd.CommandText = "SELECT COUNT(*) FROM FixedAssetMaster WHERE ASSET_NUMBER=" & AssetTxt.Text & " AND LOC_DEPT=" & DeptCodeTxt.Text & " AND UNIT_NO='" & UnitNoTxt.Text & "';"
'cmd.CommandText = "SELECT COUNT(*) FROM ScanningData WHERE ASSET_NUMBER=" & AssetTxt.Text & " AND LOC_DEPT='" & DeptCodeTxt.Text & "';"
' cmd.CommandText = "SELECT COUNT(*) FROM ScanningData WHERE ASSET_NUMBER=" & AssetTxt.Text & " AND LOC_DEPT=" & DeptCodeTxt.Text & " AND UPDATE_DATE BETWEEN'" & StartDate & "' AND '" & EndDate & "';"
cmd.Connection = Conn
rdmysql = cmd.ExecuteReader
If rdmysql.Read = True Then
reccount = Val(rdmysql.GetInt32(0))
End If
cmd.Dispose()
rdmysql.Close()
If reccount = 0 Then
strsql3 = "INSERT INTO FixedAssetMaster "
strsql3 += "(ASSET_NUMBER,DESCRIPTION,MAJOR_CATEGORY,UNITS_ASSIGNED,LOC_DEPT,DEPT_DESCRIPTION,LOC_AREA,ASSET_KEY_SEGMENT3,SERIAL_NUMBER,DATE_PLACED_IN_SERVICE,COST_BY_UNIT,MYR_COST_BY_UNIT,DATE_RETIRED,DEPRN_RESERVE_BY_UNIT,UNIT_NO,UPDATE_DATE,UPDATE_BY,NBV_BY_UNIT_USD,IT_TAG_NO) VALUES "
strsql3 += "(#ID, #DESCRIPTION, #CATEGORY, #UNIT, #CODE, #DEPT, #AREA, #LocDesc, #SN, #SERVICEDATE, #USDCOST, #MYRCOST, #RETIREDDATE, #DEPR, #UnitNo, #UPDATEDATE, #NAME, #NBV, #TAG);"
cmd = New SqlCommand
cmd.Connection = Conn
cmd.Parameters.AddWithValue("#ID", AssetTxt.Text)
cmd.Parameters.AddWithValue("#DESCRIPTION", DescTxt.Text)
cmd.Parameters.AddWithValue("#CATEGORY", CategoryTxt.Text)
Dim unit As Integer = Integer.Parse(UnitTxt.Text)
cmd.Parameters.AddWithValue("#UNIT", unit)
cmd.Parameters.AddWithValue("#CODE", DeptCodeTxt.Text)
cmd.Parameters.AddWithValue("#DEPT", DeptTxt.Text)
cmd.Parameters.AddWithValue("#AREA", LocTxt.Text)
cmd.Parameters.AddWithValue("#LocDesc", LocDescTxt.Text)
cmd.Parameters.AddWithValue("#SN", SNTxt.Text)
cmd.Parameters.AddWithValue("#SERVICEDATE", ServiceTxt.Text)
Dim USDCost As Decimal = Decimal.Parse(CostUSDTxt.Text)
cmd.Parameters.AddWithValue("#USDCOST", USDCost)
Dim MYRCost As Decimal = Decimal.Parse(CostMYRTxt.Text)
cmd.Parameters.AddWithValue("#MYRCOST", MYRCost)
cmd.Parameters.AddWithValue("#RETIREDDATE", RetiredDateTxt.Text)
Dim Depr As Decimal = Decimal.Parse(DeprTxt.Text)
cmd.Parameters.AddWithValue("#DEPR", Depr)
cmd.Parameters.AddWithValue("#UnitNo", UnitNoTxt.Text)
cmd.Parameters.AddWithValue("#UPDATEDATE", ServerDate)
cmd.Parameters.AddWithValue("#NAME", UserIDLabel.Text)
cmd.Parameters.AddWithValue("#NBV", NBVUSDTxt.Text)
cmd.Parameters.AddWithValue("#TAG", TagTxt.Text)
cmd.CommandText = strsql3
cmd.ExecuteNonQuery()
End If
I have 4 Datetimepicker. the 2 datetimepicker is on dateformat(datefrom,dateto) and the other 2 datetimepicker is on Timeformat(timefrom,timeto).
I want to search a table that display only in datagridview that will display only start on Date from and time from to date to and time to... But my code doenst work.
here's my code:
Dim fromto As String = String.Empty
fromto &= "Select * from setplan where endplan >='" & dtimefrom.Text & "'and endplan >='" & dtimeto.Text & "' and [Dateinput] >='" & ddatefrom.Text & "' and [dateinput] <= '" & ddateto.Text & "'"
Dim connection As String = ("provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Administrator\Documents\planning.accdb;Persist Security Info=False;")
Using conn As New OleDb.OleDbConnection(connection)
Using cmd As New OleDb.OleDbCommand(fromto)
With cmd
.Connection = conn
.CommandType = CommandType.Text
.CommandText = fromto
End With
Try
conn.Open()
cmd.ExecuteNonQuery()
Dim da As New OleDb.OleDbDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds)
If ds.Tables.Count > 0 Then
DataGridView1.DataSource = ds.Tables(0)
End If
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Using
End Using
End Sub
You need formatted string expressions for your date/time values:
fromto &= "Select * from setplan where endplan >= #" & ddateto.Value.ToString("yyyy'/'MM'/'dd") & " " & dtimeto.Value.ToString("HH':'mm") & "# and [dateinput] >= #" & ddatefrom.Value.ToString("yyyy'/'MM'/'dd") & " " & dtimefrom.Value.ToString("HH':'mm") & "#"
I'm trying to show a 'customized' ToolTip on an MSChart on an asp.net page, using vb.net
The chart displays OK, but I'm trying to get it to show the 'YEAR' as part of the tooltip, as well as the XY values.
I can't figure out how to do it.
Here's the code that I'm using to build the chart:
dt = New DataTable
dt.Columns.Add("Topic")
dt.Columns.Add("Value")
dt.Columns.Add("Year")
For i = 0 To t_YEARS.Count - 1
Sql = "SELECT att_Topic, att_Value, att_Year from Att "
Sql += " WHERE att_Year = '" & t_YEARS(i) & "' "
conn.ConnectionString = strConnString
conn.Open()
cmd = New SqlCommand(Sql, conn)
dr = cmd.ExecuteReader
While dr.Read
dt.Rows.Add(dr(0), dr(1), dr(2))
End While
dr.Close()
cmd.Dispose()
conn.Close()
Next
Chart1.DataSource = dt
Chart1.Series("Series1").XValueMember = "Topic"
Chart1.Series("Series1").YValueMembers = "Value"
Chart1.Series("Series1").ToolTip = "#VALX - #VALY"
Chart1.ChartAreas("ChartArea1").Area3DStyle.Enable3D = True
Chart1.DataBind()
Well, there may be a better answer, but I figured out a work-around anyhow ... I'm adding the YEAR to the axislabel. Then, in chart1_customize, changing the color of the bar, based on different axislabel. Seems to work.
dt = New DataTable
dt.Columns.Add("Topic")
dt.Columns.Add("Value")
dt.Columns.Add("Year")
For i = 0 To t_YEARS.Count - 1
showDATA = False
Sql = "SELECT att_Topic, att_Value, att_Year, att_Data from BWS_Att "
If (RBL_LIMIT.SelectedValue = 1) Then
showDATA = True
Sql += " WHERE att_Attrib = 'Location' "
Sql += " AND att_Data IN ('" & String.Join("','", t_LOCS) & "')"
ElseIf (RBL_LIMIT.SelectedValue = 2) Then
showDATA = True
Sql += " WHERE att_Attrib = 'Department' "
Sql += " AND att_Data IN ('" & String.Join("','", t_DEPTS) & "')"
Else
Sql += " WHERE att_Attrib = 'Company' "
End If
Sql += " AND att_Year = '" & t_YEARS(i) & "' "
Sql += " AND att_Topic IN ('" & String.Join("','", t_CATS) & "')"
Sql += " Order By att_ind"
conn.ConnectionString = strConnString
conn.Open()
cmd = New SqlCommand(Sql, conn)
dr = cmd.ExecuteReader
While dr.Read
'dt.Rows.Add(dr(0), dr(1), dr(2))
thisYR = dr(2).ToString
If (lastYR <> thisYR) Then
Chart1.Series("Series1").Points.Add(vbEmpty)
Chart1.Series("Series1").Points.Add(vbEmpty)
lastYR = thisYR
End If
If (showDATA = True) Then
Chart1.Series("Series1").Points.AddXY(dr(2).ToString & "|" & dr(3).ToString & ":" & dr(0).ToString, dr(1))
Else
Chart1.Series("Series1").Points.AddXY(dr(2).ToString & ":" & dr(0).ToString, dr(1))
End If
Chart1.Series("Series1").ToolTip = " #AXISLABEL | #VALY"
End While
dr.Close()
cmd.Dispose()
conn.Close()
Next
~~~~~~~~~~
Private Sub Chart1_Customize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Chart1.Customize
Dim C() As Drawing.Color = { _
Drawing.Color.Khaki, _
Drawing.Color.DarkSalmon, _
Drawing.Color.Goldenrod, _
Drawing.Color.MediumAquamarine, _
Drawing.Color.Tan _
}
Dim CN As Int16 = 0
Dim thisC As Int16 = 0
Dim LAST As String = String.Empty
For Each dp As System.Web.UI.DataVisualization.Charting.DataPoint In Chart1.Series("Series1").Points
Dim x As Array = dp.AxisLabel.Split(":")
If (x(0) <> "") Then
Dim H As String = x(0)
If (LAST <> H) Then
CN += 1
LAST = H
thisC = (CN Mod 5)
End If
dp.Color = C(thisC)
End If
Next
End Sub
I have this code and its coming up with an INSERT INTO statement error...
Its probably something but I have been at it for a while... please help.
'Add items to db'
Function recordOrder()
objDT = Session("Cart")
Dim intCounter As Integer
For intCounter = 0 To objDT.Rows.Count - 1
objDR = objDT.Rows(intCounter)
Dim con2 As New System.Data.OleDb.OleDbConnection
Dim myPath2 As String
myPath2 = Server.MapPath("faraxday.mdb")
con2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & myPath2 & ";"
Dim myCommand2 As New System.Data.OleDb.OleDbCommand
myCommand2.CommandText = "INSERT INTO order(order_date, coupon_id, customer_id, quantity) values('" & System.DateTime.Now & "','" & Int32.Parse(objDR("ID")) & "','" & Int32.Parse(custID) & "','" & Int32.Parse(objDR("quantity")) &"')"
myCommand2.Connection = con2
con2.Open()
myCommand2.ExecuteReader()
con2.Close()
test.Text += "Order ID: " & objDR("ID") & "Order Date: " & System.DateTime.Now & ", Cust ID: " & custID & ", Quantity: " & objDR("quantity") &" "
Next
End Function
I think you are getting an error by not enclosing the Date inside Pound signs. You have to do this in Jet (Access) when using variables not parameters.
VALUES('#" & DateTime.Now.Date & "#',...
I also took the liberty of refactoring this code for you since you are creating a new connection for each record which is bad news. Use a Try Catch Finally block and move all that stuff outside the For Loop (please see below)
Function recordOrder()
objDT = Session("Cart")
Dim intCounter As Integer
Dim con2 As New System.Data.OleDb.OleDbConnection
Dim myPath2 As String
myPath2 = Server.MapPath("faraxday.mdb")
con2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" <-- etc
Dim myCommand2 As New System.Data.OleDb.OleDbCommand
myCommand2.Connection = con2
con2.Open()
Try
For intCounter = 0 To obDT.Rows.Count - 1
objDR = objDT.Rows(intCounter)
myCommand2.CommandText = "INSERT INTO order(order_date,coupon_id,customer_id,quantity)" _
& "VALUES ('#" & System.DateTime.Now.Date & "#','" & Int32.Parse(objDR("ID")) & "','" & Int32.Parse(custID) _
& "','" & Int32.Parse(objDR("quantity")) & "')"
myCommand2.ExecuteReader()
Next
Catch ex As Exception
'handle errors here
Finally
If con2.State = ConnectionState.Open Then
con2.Close()
End If
End Try
End Function
Remember to mark as answered if this helps.
I've sorted it out by removing the single quotes. Thanks everybody to contributed to this.