multiple if statements missing data - mysql

Just want to ask why this wont work for me?
I'm trying to bring back data for booking system (or something which like that).
The problem is that it only go to only one if statement and ignore the second one.
Using VB.net and trying to connect to MySQL database.
Thanks all...
Petr
thanks for answers guys i will try all the problem is that if its not = to let say Monday then it should make the color of the check-box white.
I will try the select case and see.
I did some changes add there checkbox lists that it make it easier. The problem is to clear the checkbox on different days.
CheckBoxListMon.BackColor = Drawing.Color.White
CheckBoxListMon.Enabled = True
CheckBoxListMon.ClearSelection()
This make the checkbox enabled and not selected but I still cant can't click on them they are disabled.
Anyone have some idea?
Try
strQuery = "SELECT BookingDate, BookingTime,BookRegUserID,Booked FROM bookings"
MySQLCmd = New MySqlCommand(strQuery, dbCon)
dbCon.Open()
DR = MySQLCmd.ExecuteReader
While DR.Read
bookDate = DR.Item("BookingDate")
bookTime = DR.Item("BookingTime")
bookRegID = DR.Item("BookRegUserID")
booked = DR.Item("Booked")
Select Case True
Case bookDate = lblMonday.Text And CheckBoxListMon.Items.FindByValue(test) IsNot Nothing
CheckBoxListMon.Items.FindByValue(bookTime).Enabled = False
CheckBoxListMon.Items.FindByValue(bookTime).Selected = True
CheckBoxListMon.Items.FindByValue(bookTime).Attributes.Add("Style", "color: red;")
Case bookDate = lblTuesday.Text And CheckBoxListTue.Items.FindByValue(test) IsNot Nothing
CheckBoxListTue.Items.FindByValue(bookTime).Enabled = False
CheckBoxListTue.Items.FindByValue(bookTime).Selected = True
CheckBoxListTue.Items.FindByValue(bookTime).Attributes.Add("Style", "color: red;")
End While
DR.Close()
dbCon.Close()
Catch ex As Exception
End Try

I think Isee the problem now. You dont want to flip the comboboxes back if they do not match. Lets say you have Monday Tuesday being returned in your result set. The first row will flip monday to true and tuesday to false, the second will set monday to false - which I do not think you want - and set tuesday to true, leaving everything being decided by the last row. The answer is to set them all to false before processing the rows, and only set to true if you get a match, otherwise ignore it.
CbMon10.BackColor = Drawing.Color.White
CbMon10.Checked = False
CbMon10.Enabled = True
CbTue10.BackColor = Drawing.Color.White
CbTue10.Checked = False
CbTue10.Enabled = True
While DR.Read
bookDate = DR.Item("BookingDate")
bookTime = DR.Item("BookingTime")
bookRegID = DR.Item("BookRegUserID")
booked = DR.Item("Booked")
Select Case True
Case bookDate = lblMonday.Text And bookTime = CbMon10.Text
CbMon10.BackColor = Drawing.Color.Red
CbMon10.Checked = True
CbMon10.Enabled = False
Case bookDate = lblTuesday.Text And bookTime = CbTue10.Text
CbTue10.BackColor = Drawing.Color.Red
CbTue10.Checked = True
CbTue10.Enabled = False
End Select
End While

You should use if-else-if ladder like this :
If bookDate = lblMonday.Text And bookTime = CbMon10.Text Then
CbMon10.BackColor = Drawing.Color.Red
CbMon10.Checked = True
CbMon10.Enabled = False
Else If bookDate = lblTuesday.Text And bookTime = CbTue10.Text Then
CbTue10.BackColor = Drawing.Color.Red
CbTue10.Checked = True
CbTue10.Enabled = False
Else
CbTue10.BackColor = Drawing.Color.White
CbTue10.Checked = False
CbTue10.Enabled = True
End If

Instead of multiple if's you can use it like this:-
If (bookDate = lblMonday.Text And bookTime = CbMon10.Text) or (bookDate = lblTuesday.Text And bookTime = CbTue10.Text) Then
CbMon10.BackColor = Drawing.Color.Red
CbMon10.Checked = True
CbMon10.Enabled = False
Else
CbMon10.BackColor = Drawing.Color.White
CbMon10.Checked = False
CbMon10.Enabled = True
End If

Related

How to render a new page in the current page itself in Rails?

I hava a view index.html.erb in which the selection of product,client and date_range is given. On selecting those values, an invoice is created which is given in new.html.erb.
In invoices controller, I have logic to store data in corresponding tables and then render new.html.erb. It comes as a separate page. I need to have invoice table ie., new.html.erb in the same page ie., index page.
if params[:commit] == 'Create Invoice'
#invoice = Invoice.new(invoice_params)
#client_id = params[:invoices][:client_id]
#project_id = params[:invoices][:project_id]
#from = params[:invoices][:fromdate]
#to = params[:invoices][:todate]
#totalhrs = params[:invoices][:totalbilledhrs]
#timesheet = Timesheet.where("client_id = ? and project_id = ?
and is_billed= 'true' and timesheetdate between ?
and ?",#client_id,#project_id,#from,#to)
if #invoice.save
end
#task = #timesheet.uniq.pluck("task_id");
#task.each do |t|
#invoice_task = InvoiceTaskDetail.new
#invoice_task.invoice_id = Invoice.last.id
#invoice_task.task_id = t
#invoice_task.task_name = Task.find(t).task_name
#invoice_task.totalbilledhrs = 0
#invoice_task.totalamt = 0
if #invoice_task.save
end
#timesheet1 = #timesheet.all.where("task_id=?",t)
#subtask = #timesheet1.uniq.pluck("role_id")
#subtask.each do |sub|
#invoice_subtask = InvoiceSubtask.new
#invoice_subtask.invoice_task_detail_id =
InvoiceTaskDetail.last.id
#invoice_subtask.role_id = sub
#invoice_subtask.role_description =
Role.find(sub).role_description
#timesheet2 = #timesheet1.all.where("role_id = ?",sub)
#timesheet2.select("role_id,sum(hours) as hrs, sum(rate) as
totrate").group("role_id").each do |tt|
#invoice_subtask.billedhrs =tt.hrs
#invoice_subtask.billedrate = tt.totrate
#invoice_subtask.totalamount = tt.hrs * tt.totrate
end
if #invoice_subtask.save
end
end
InvoiceSubtask.where("invoice_task_detail_id
=?",InvoiceTaskDetail.last.id).select("invoice_task_detail_id,
sum(billedhrs) as totalhrs,sum(totalamount) as
tot").group("invoice_task_detail_id").each do |ttt|
#invoice_task.update_attribute(:totalbilledhrs,ttt.totalhrs)
#invoice_task.update_attribute(:totalamt,ttt.tot)
end
end
InvoiceTaskDetail.where("invoice_id =
?",Invoice.last.id).select("invoice_id,sum(totalbilledhrs) as
total,sum(totalamt) as tot").group("invoice_id").each do |tt1|
#invoice.update_attribute(:totalbilledhrs, tt1.total)
#invoice.update_attribute(:invoiceamt, tt1.tot)
end
#invoice_tasks =
InvoiceTaskDetail.where("invoice_id=?",#invoice.id)
render 'new'
else
#invoices = Invoice.all
#client_id = params[:invoices][:client_id]
#project_id = params[:invoices][:project_id]
#from = params[:invoices][:fromdate]
#to = params[:invoices][:todate]
#invoice = #invoices.where("client_id= ? and project_id = ? and
fromdate = ? and todate = ?", #client_id, #project_id, #from,
#to).last
if #invoice.nil?
flash[:error] = "Sorry!! No Invoices available for the given
client/project/date range"
redirect_to invoices_path
else
#invoice_tasks = InvoiceTaskDetail.where("invoice_id =
?",#invoice.id)
render 'new'
end
end
Now, I want the new page table(invoice table) within the index page.
How to accomplish this?
First of all, the new.html.erb should not create anything. You should have an html form in there that, when submitted, will call the create action on the corresponding controller (in your case, invoices_controller).
Once you're done with creating the invoice, you should either redirect to the newly created invoice (so the InvoicesController#show) or redirect to all the invoices for instance (InvoicesController#index), but not the new page.

VBA nested if inquiry

I am trying to write write a nested if statement in VBA. In cobol, I would typically use the evaluate clause. But what do I use in VBA so as to avoid a long loop.
Example.
if cmbfield = "green" then
me.frame1.enable = true
else
me.frame2.enable = false
me.frame3.enable = false
end if
if cmbfield = "red" then
me.frame2.enable = true
else
me.frame1.enable = false
me.frame3.enable = false
end if
if cmbfield = "white" then
me.frame3.enable = true
else
me.frame1.enable = false
me.frame2.enable = false
end if
In the example you gave I'd use a switch command:
http://www.techonthenet.com/excel/formulas/case.php
Select Case test_expression
Case condition_1
result_1
Case condition_2
result_2
...
Case condition_n
result_n
Case Else
result_else
End Select
You could also do if ... elseif ... end if
http://www.techonthenet.com/excel/formulas/if_then.php
If condition_1 Then
result_1
ElseIf condition_2 Then
result_2
...
ElseIf condition_n Then
result_n
Else
result_else
End If
I do it this way:
Me.frame1.enabled = (cmbfield = "green")
Me.frame2.enabled = (cmbfield = "red")
Me.frame3.enabled = (cmbfield = "white")
Dim isGreen as Boolean, isRed as Boolean, isWhite as Boolean
isGreen = (cmbfield = "green")
isRed = (cmbfield = "red")
isWhite = (cmbfield = "white")
me.frame1.enabled = isGreen
me.frame2.enabled = isRed
me.frame3.enabled = isWhite
This is a shorter way to write the same code. Should work modulo syntax; hope this helps.

Mysql Error - Update Query

do you find any issue in these below MySQL query. Actually this Insert query is not working. the tools picks the values from FORM controls correctly but it is not updating.
the values ain't update in MySQL DB. the coding brings the form values correctly but it is not updating in MySQL DB
actually the query where i am using in VB.Net (VS2010)
Private Sub btnupdate_Click(sender As System.Object, e As System.EventArgs) Handles btnupdate.Click
Dim ch_date As Date = dtpdate.Value
If ch_date = getToday(Now) Then
checkdate(ch_date)
Else
checkdate(ch_date)
End If
cleanfields()
End Sub
Function checkdate(ByVal chdate As Date)
Dim tmpreader As MySqlDataReader
Dim usr As String
'Dim dtp_date As Date = dtpdate.Value
usr = getUserName()
usr = getFullName(getUserName())
Try
If main_form.mySQLconn1.State = ConnectionState.Closed Then
main_form.mySQLconn1.Open()
End If
main_form.cmdproductivity.CommandText = "SELECT * FROM productivity WHERE productivity_date = #productivity_date"
main_form.cmdproductivity.Parameters("#productivity_date").Value = chdate
tmpreader = main_form.cmdproductivity.ExecuteReader()
If tmpreader.HasRows Then
main_form.cmdproductivity.CommandText = "UPDATE productivity SET agent = #agent, productivity_date = #productivity_date, actual_date = #actual_date, total_count = #total_count, eq_pr = #eq_pr, c_rebook=#c_rebook, c_nonwatson=#c_nonwatson, c_coa=#c_coa, c_watson=#c_watson, c_velocity=#c_velocity, c_quote=#c_quote, c_crd=#c_crd, c_eclaims=#c_eclaims, c_ecalls=#c_ecalls, c_xi=#c_xi, c_brazil=#c_brazil, c_cancel=#c_cancel, c_queries=#c_queries, c_partrebook=#c_partrebook, c_nci=#c_nci, c_phil=#c_phil, c_qc=#c_qc, c_watsonqc=#c_watsonqc, c_monitor=#c_monitor, c_enduser=#c_enduser, c_idoc=#c_idoc, c_servercancel=#c_servercancel, eq_rebook=#eq_rebook, eq_nonwatson=#eq_nonwatson, eq_coa=#eq_coa, eq_watson=#eq_watson, eq_velocity=#eq_velocity, eq_quote=#eq_quote, eq_crd=#eq_crd, eq_eclaims=#eq_eclaims, eq_ecalls=#eq_ecalls, eq_xi=#eq_xi, eq_brazil=#eq_brazil, eq_cancel=#eq_cancel, eq_queries=#eq_queries, eq_partrebook=#eq_partrebook, eq_nci=#eq_nci, eq_phil=#eq_phil, eq_qc=#eq_qc, eq_watsonqc=#eq_watsonqc, eq_monitor=#eq_monitor, eq_enduser=#eq_enduser, eq_idoc=#eq_idoc, eq_servercancel=#eq_servercancel WHERE productivity_date = #productivity_date"
main_form.cmdproductivity.Parameters("#agent").Value = Trim(usr)
main_form.cmdproductivity.Parameters("#productivity_date").Value = Trim(chdate)
main_form.cmdproductivity.Parameters("#actual_date").Value = getToday(Now)
main_form.cmdproductivity.Parameters("#total_count").Value = Trim(txtcount.Text)
main_form.cmdproductivity.Parameters("#eq_pr").Value = Trim(txtEQPRs.Text)
main_form.cmdproductivity.Parameters("#c_rebook").Value = Trim(txtrebook.Text)
main_form.cmdproductivity.Parameters("#c_nonwatson").Value = Trim(txtnonwatson.Text)
main_form.cmdproductivity.Parameters("#c_coa").Value = Trim(txtcoa.Text)
main_form.cmdproductivity.Parameters("#c_watson").Value = Trim(txtwatson.Text)
main_form.cmdproductivity.Parameters("#c_velocity").Value = Trim(txtvelocity.Text)
main_form.cmdproductivity.Parameters("#c_quote").Value = Trim(txtquote.Text)
main_form.cmdproductivity.Parameters("#c_crd").Value = Trim(txtcrd.Text)
main_form.cmdproductivity.Parameters("#c_eclaims").Value = Trim(txteclaims.Text)
main_form.cmdproductivity.Parameters("#c_ecalls").Value = Trim(txtecalls.Text)
main_form.cmdproductivity.Parameters("#c_xi").Value = Trim(txtxi.Text)
main_form.cmdproductivity.Parameters("#c_brazil").Value = Trim(txtbrazil.Text)
main_form.cmdproductivity.Parameters("#c_cancel").Value = Trim(txtcancel.Text)
main_form.cmdproductivity.Parameters("#c_queries").Value = Trim(txtqueries.Text)
main_form.cmdproductivity.Parameters("#c_partrebook").Value = Trim(txtpartrebook.Text)
main_form.cmdproductivity.Parameters("#c_nci").Value = Trim(txtnci.Text)
main_form.cmdproductivity.Parameters("#c_phil").Value = Trim(txtphil.Text)
main_form.cmdproductivity.Parameters("#c_qc").Value = Trim(txtqc.Text)
main_form.cmdproductivity.Parameters("#c_watsonqc").Value = Trim(txtwatsonqc.Text)
main_form.cmdproductivity.Parameters("#c_monitor").Value = Trim(txtmonitor.Text)
main_form.cmdproductivity.Parameters("#c_enduser").Value = Trim(txtenduser.Text)
main_form.cmdproductivity.Parameters("#c_idoc").Value = Trim(txtidoc.Text)
main_form.cmdproductivity.Parameters("#c_servercancel").Value = Trim(txtservercancel.Text)
main_form.cmdproductivity.Parameters("#eq_rebook").Value = Trim(txtEQrebook.Text)
main_form.cmdproductivity.Parameters("#eq_nonwatson").Value = Trim(txtEQnonwatson.Text)
main_form.cmdproductivity.Parameters("#eq_coa").Value = Trim(txtEQcoa.Text)
main_form.cmdproductivity.Parameters("#eq_watson").Value = Trim(txtEQwatson.Text)
main_form.cmdproductivity.Parameters("#eq_velocity").Value = Trim(txtEQvelocity.Text)
main_form.cmdproductivity.Parameters("#eq_quote").Value = Trim(txtEQquote.Text)
main_form.cmdproductivity.Parameters("#eq_crd").Value = Trim(txtEQcrd.Text)
main_form.cmdproductivity.Parameters("#eq_eclaims").Value = Trim(txtEQeclaims.Text)
main_form.cmdproductivity.Parameters("#eq_ecalls").Value = Trim(txtEQecalls.Text)
main_form.cmdproductivity.Parameters("#eq_xi").Value = Trim(txtEQxi.Text)
main_form.cmdproductivity.Parameters("#eq_brazil").Value = Trim(txtEQbrazil.Text)
main_form.cmdproductivity.Parameters("#eq_cancel").Value = Trim(txtEQcancel.Text)
main_form.cmdproductivity.Parameters("#eq_queries").Value = Trim(txtEQqueries.Text)
main_form.cmdproductivity.Parameters("#eq_partrebook").Value = Trim(txtEQpartrebook.Text)
main_form.cmdproductivity.Parameters("#eq_nci").Value = Trim(txtEQnci.Text)
main_form.cmdproductivity.Parameters("#eq_phil").Value = Trim(txtEQphil.Text)
main_form.cmdproductivity.Parameters("#eq_qc").Value = Trim(txtEQqc.Text)
main_form.cmdproductivity.Parameters("#eq_watsonqc").Value = Trim(txtEQwatsonqc.Text)
main_form.cmdproductivity.Parameters("#eq_monitor").Value = Trim(txtEQmonitor.Text)
main_form.cmdproductivity.Parameters("#eq_enduser").Value = Trim(txtEQenduser.Text)
main_form.cmdproductivity.Parameters("#eq_idoc").Value = Trim(txtEQidoc.Text)
main_form.cmdproductivity.Parameters("#eq_servercancel").Value = Trim(txtEQservercancel.Text)
Else
'main_form.cmdproductivity.CommandText = "INSERT INTO productivity " _
' & "(agent,productivity_date,actual_date,total_count,eq_pr,c_rebook,c_nonwatson,c_coa,c_watson,c_velocity,c_quote,c_crd,c_eclaims,c_ecalls,c_xi,c_brazil,c_cancel,c_queries,c_partrebook,c_nci,c_phil,c_qc,c_watsonqc,c_monitor,c_enduser,c_idoc,c_servercancel,eq_rebook,eq_nonwatson,eq_coa,eq_watson,eq_velocity,eq_quote,eq_crd,eq_eclaims,eq_ecallseq_xi,eq_brazil,eq_cancel,eq_queries,eq_partrebook,eq_nci,eq_phil,eq_qc,eq_watsonqc,eq_monitor,eq_enduser,eq_idoc,eq_servercancel VALUES" _
' & "(#agent,#productivity_date,#actual_date,#total_count,#eq_pr,#c_rebook,#c_nonwatson,#c_coa,#c_watson,#c_velocity,#c_quote,#c_crd,#c_eclaims,#c_ecalls,#c_xi,#c_brazil,#c_cancel,#c_queries,#c_partrebook,#c_nci,#c_phil,#c_qc,#c_watsonqc,#c_monitor,#c_enduser,#c_idoc,#c_servercancel,#eq_rebook,#eq_nonwatson,#eq_coa,#eq_watson,#eq_velocity,#eq_quote,#eq_crd,#eq_eclaims,#eq_ecalls,#eq_xi,#eq_brazil,#eq_cancel,#eq_queries,#eq_partrebook,#eq_nci,#eq_phil,#eq_qc,#eq_watsonqc,#eq_monitor,#eq_enduser,#eq_idoc,#eq_servercancel)"
main_form.cmdproductivity.CommandText = "INSERT INTO productivity(agent, productivity_date, actual_date, total_count, eq_pr, c_rebook, c_nonwatson, c_coa, c_watson, c_velocity, c_quote, c_crd, c_eclaims, c_ecalls, c_xi, c_brazil, c_cancel, c_queries, c_partrebook, c_nci, c_phil, c_qc, c_watsonqc, c_monitor, c_enduser, c_idoc, c_servercancel, eq_rebook, eq_nonwatson, eq_coa, eq_watson, eq_velocity, eq_quote, eq_crd, eq_eclaims, eq_ecalls, eq_xi, eq_brazil, eq_cancel, eq_queries, eq_partrebook, eq_nci, eq_phil, eq_qc, eq_watsonqc, eq_monitor, eq_enduser, eq_idoc, eq_servercancel) VALUES (#agent,#productivity_date,#actual_date,#total_count,#eq_pr,#c_rebook,#c_nonwatson,#c_coa,#c_watson,#c_velocity,#c_quote,#c_crd,#c_eclaims,#c_ecalls,#c_xi,#c_brazil,#c_cancel,#c_queries,#c_partrebook,#c_nci,#c_phil,#c_qc,#c_watsonqc,#c_monitor,#c_enduser,#c_idoc,#c_servercancel,#eq_rebook,#eq_nonwatson,#eq_coa,#eq_watson,#eq_velocity,#eq_quote,#eq_crd,#eq_eclaims,#eq_ecalls,#eq_xi,#eq_brazil,#eq_cancel,#eq_queries,#eq_partrebook,#eq_nci,#eq_phil,#eq_qc,#eq_watsonqc,#eq_monitor,#eq_enduser,#eq_idoc,#eq_servercancel)"
main_form.cmdproductivity.Parameters("#agent").Value = Trim(usr)
main_form.cmdproductivity.Parameters("#productivity_date").Value = Trim(chdate)
main_form.cmdproductivity.Parameters("#actual_date").Value = getToday(Now)
main_form.cmdproductivity.Parameters("#total_count").Value = Trim(txtcount.Text)
main_form.cmdproductivity.Parameters("#eq_pr").Value = Trim(txtEQPRs.Text)
main_form.cmdproductivity.Parameters("#c_rebook").Value = Trim(txtrebook.Text)
main_form.cmdproductivity.Parameters("#c_nonwatson").Value = Trim(txtnonwatson.Text)
main_form.cmdproductivity.Parameters("#c_coa").Value = Trim(txtcoa.Text)
main_form.cmdproductivity.Parameters("#c_watson").Value = Trim(txtwatson.Text)
main_form.cmdproductivity.Parameters("#c_velocity").Value = Trim(txtvelocity.Text)
main_form.cmdproductivity.Parameters("#c_quote").Value = Trim(txtquote.Text)
main_form.cmdproductivity.Parameters("#c_crd").Value = Trim(txtcrd.Text)
main_form.cmdproductivity.Parameters("#c_eclaims").Value = Trim(txteclaims.Text)
main_form.cmdproductivity.Parameters("#c_ecalls").Value = Trim(txtecalls.Text)
main_form.cmdproductivity.Parameters("#c_xi").Value = Trim(txtxi.Text)
main_form.cmdproductivity.Parameters("#c_brazil").Value = Trim(txtbrazil.Text)
main_form.cmdproductivity.Parameters("#c_cancel").Value = Trim(txtcancel.Text)
main_form.cmdproductivity.Parameters("#c_queries").Value = Trim(txtqueries.Text)
main_form.cmdproductivity.Parameters("#c_partrebook").Value = Trim(txtpartrebook.Text)
main_form.cmdproductivity.Parameters("#c_nci").Value = Trim(txtnci.Text)
main_form.cmdproductivity.Parameters("#c_phil").Value = Trim(txtphil.Text)
main_form.cmdproductivity.Parameters("#c_qc").Value = Trim(txtqc.Text)
main_form.cmdproductivity.Parameters("#c_watsonqc").Value = Trim(txtwatsonqc.Text)
main_form.cmdproductivity.Parameters("#c_monitor").Value = Trim(txtmonitor.Text)
main_form.cmdproductivity.Parameters("#c_enduser").Value = Trim(txtenduser.Text)
main_form.cmdproductivity.Parameters("#c_idoc").Value = Trim(txtidoc.Text)
main_form.cmdproductivity.Parameters("#c_servercancel").Value = Trim(txtservercancel.Text)
main_form.cmdproductivity.Parameters("#eq_rebook").Value = Trim(txtEQrebook.Text)
main_form.cmdproductivity.Parameters("#eq_nonwatson").Value = Trim(txtEQnonwatson.Text)
main_form.cmdproductivity.Parameters("#eq_coa").Value = Trim(txtEQcoa.Text)
main_form.cmdproductivity.Parameters("#eq_watson").Value = Trim(txtEQwatson.Text)
main_form.cmdproductivity.Parameters("#eq_velocity").Value = Trim(txtEQvelocity.Text)
main_form.cmdproductivity.Parameters("#eq_quote").Value = Trim(txtEQquote.Text)
main_form.cmdproductivity.Parameters("#eq_crd").Value = Trim(txtEQcrd.Text)
main_form.cmdproductivity.Parameters("#eq_eclaims").Value = Trim(txtEQeclaims.Text)
main_form.cmdproductivity.Parameters("#eq_ecalls").Value = Trim(txtEQecalls.Text)
main_form.cmdproductivity.Parameters("#eq_xi").Value = Trim(txtEQxi.Text)
main_form.cmdproductivity.Parameters("#eq_brazil").Value = Trim(txtEQbrazil.Text)
main_form.cmdproductivity.Parameters("#eq_cancel").Value = Trim(txtEQcancel.Text)
main_form.cmdproductivity.Parameters("#eq_queries").Value = Trim(txtEQqueries.Text)
main_form.cmdproductivity.Parameters("#eq_partrebook").Value = Trim(txtEQpartrebook.Text)
main_form.cmdproductivity.Parameters("#eq_nci").Value = Trim(txtEQnci.Text)
main_form.cmdproductivity.Parameters("#eq_phil").Value = Trim(txtEQphil.Text)
main_form.cmdproductivity.Parameters("#eq_qc").Value = Trim(txtEQqc.Text)
main_form.cmdproductivity.Parameters("#eq_watsonqc").Value = Trim(txtEQwatsonqc.Text)
main_form.cmdproductivity.Parameters("#eq_monitor").Value = Trim(txtEQmonitor.Text)
main_form.cmdproductivity.Parameters("#eq_enduser").Value = Trim(txtEQenduser.Text)
main_form.cmdproductivity.Parameters("#eq_idoc").Value = Trim(txtEQidoc.Text)
main_form.cmdproductivity.Parameters("#eq_servercancel").Value = Trim(txtEQservercancel.Text)
End If
Catch ex As Exception
MsgBox("Database Error: " & ex.ToString() & vbCrLf & "The error have been logged .... ", MsgBoxStyle.OkOnly, main_form.dbErrTitle)
writeLogs("Database Error: " & ex.ToString())
Finally
main_form.mySQLconn1.Close()
End Try
Return True
End Function
I don't calculate your column number, but do you miss one column at end? where is the last id which exists in column but not in VALUSE part:
(eq_servercancel, id) vs
(#eq_servercancel)
It would really help if you edit your answer with the error you are getting, but at a glance:
You are adding "id" to you column list in the INSERT statement, but you do not have a "id" value in your VALUES statement. So either remove "id" from the INSERT statement or send through a value for "id".

index is outside the bounds of array

My try/catch expression always gives me a error message that "index is outside the bounds of array" however the function is working perfectly the way it should work. The only problem is that annoying mistake.
this is the code I'm using:
Try
conn.Open()
Dim Qwery As String = "SELECT a.accid AS 'No', a.setID AS 'ID', l.class AS 'Type', CONCAT(fname,' ',middname,' ',lname ) AS 'Name', date(a.bdate) AS 'BirthDate', l.mail AS 'Acount Name', l.login AS 'Login', l.gender AS 'Gender', l.position AS 'Position', l.department AS 'Department', l.tel AS 'Tel No', l.localno AS 'Office Tel', l.cellno AS 'Cell Phone', l.alt_email AS 'Other Email', l.classif AS 'Classification', l.status AS 'Status' FROM entry a, liist l WHERE a.accid = l.accid AND l.status = '0' ORDER BY a.accid Desc"
Dim smd As MySqlCommand
Dim myreader As MySqlDataReader
smd = New MySqlCommand(Qwery, myconn)
myreader = smd.ExecuteReader
If myreader.Read() = True Then
IdBox.Text = myreader.GetValue(0)
IdNumBox.Text = myreader.GetValue(1)
TypeBox.Text = myreader.GetValue(2)
NameBox.Text = myreader.GetValue(3)
BDayBox.Text = myreader.GetValue(4)
AcNameBox.Text = myreader.GetValue(5)
PassBox.Text = myreader.GetValue(6)
GenBox.Text = myreader.GetValue(7)
PositionBox.Text = myreader.GetValue(8)
DepartmentBox.Text = myreader.GetValue(9)
TelBox.Text = myreader.GetValue(10)
OfficeBox.Text = myreader.GetValue(11)
CellBox.Text = myreader.GetValue(12)
altMailBox.Text = myreader.GetValue(13)
ClassBox.Text = myreader.GetValue(14)
StatusBox.Text = myreader.GetValue(15)
End If
conn.Close()
Catch ex As Exception
MsgBox("Error: " & ex.Message.ToString())
conn.Close()
End Try
The interesting point that I tried removing assignments of labels one by one. And up to myreader.GetValue(3) the error does not appear. If I try assigning more lables it appears again.
Does anyone know the reason behind?
Check the condition for the datareader has greater than 15 rows.then access your code .
myreader = smd.ExecuteReader
If myreader.Read() = True Then
if myreader.GetSchemaTable().Rows.Count >= 15 then
IdBox.Text = myreader.GetValue(0)
IdNumBox.Text = myreader.GetValue(1)
TypeBox.Text = myreader.GetValue(2)
NameBox.Text = myreader.GetValue(3)
BDayBox.Text = myreader.GetValue(4)
AcNameBox.Text = myreader.GetValue(5)
PassBox.Text = myreader.GetValue(6)
GenBox.Text = myreader.GetValue(7)
PositionBox.Text = myreader.GetValue(8)
DepartmentBox.Text = myreader.GetValue(9)
TelBox.Text = myreader.GetValue(10)
OfficeBox.Text = myreader.GetValue(11)
CellBox.Text = myreader.GetValue(12)
altMailBox.Text = myreader.GetValue(13)
ClassBox.Text = myreader.GetValue(14)
StatusBox.Text = myreader.GetValue(15)
End If
End If
or try datareaderObject.RecordsAffected >= 15
i think in your query date(a.bdate) AS 'BirthDate' is throwing the error
may be the reason is that a.bdate is null value and can not be converted into date..

Capture primary key value

I'm adding a record to a table using the following code:
Dim rs1 As DAO.Recordset
Set rs1 = CurrentDb.OpenRecordset("QUOTE-Run", dbOpenDynaset)
rs1.AddNew
rs1.Fields("[QuoteNumber]").value = [txtQuoteNumber].value
rs1.Fields("[LeadTime]").value = [txtLeadTime].value
rs1.Fields("[Qty]").value = [txtQty].value
rs1.Fields("[Title]").value = [txtTitle].value
rs1.Fields("[Date]").value = VBA.DateTime.Date
rs1.Fields("[Time]").value = VBA.DateTime.Time
rs1.Fields("[InitiatedBy]").value = Application.CurrentUser
rs1.Fields("[IncompleteProblemNotes]").value = [txtIncompleteProblemNotes].value
rs1.Fields("[CustomerNotes]").value = [txtCustomerNotes].value
rs1.Fields("[Memo]").value = [txtMemo].value
rs1.Fields("[Memo1]").value = [txtMemo1].value
rs1.Fields("[PrefferedQuoteRunSelect]").value = [txtPrefferedQuoteRunSelect].value
rs1.Fields("[CombinedRun]").value = [chkCombinedRun].value
rs1.Update
When creating the record there is an AutoNumber primary key field called RunID that gets a value. I need to know what that value is so I can use it later in the code. What is the easiest way of capturing that value?
The easiest way I can think of for you to get the value of RunID is declaring a variable and setting that variable equal to the field before updating the record. Something like this:
Dim rs1 As DAO.Recordset
Set rs1 = CurrentDb.OpenRecordset("QUOTE-Run", dbOpenDynaset)
Dim TempRunID As Long
rs1.AddNew
rs1.Fields("[QuoteNumber]").value = [txtQuoteNumber].value
rs1.Fields("[LeadTime]").value = [txtLeadTime].value
rs1.Fields("[Qty]").value = [txtQty].value
rs1.Fields("[Title]").value = [txtTitle].value
rs1.Fields("[Date]").value = VBA.DateTime.Date
rs1.Fields("[Time]").value = VBA.DateTime.Time
rs1.Fields("[InitiatedBy]").value = Application.CurrentUser
rs1.Fields("[IncompleteProblemNotes]").value = [txtIncompleteProblemNotes].value
rs1.Fields("[CustomerNotes]").value = [txtCustomerNotes].value
rs1.Fields("[Memo]").value = [txtMemo].value
rs1.Fields("[Memo1]").value = [txtMemo1].value
rs1.Fields("[PrefferedQuoteRunSelect]").value = [txtPrefferedQuoteRunSelect].value
rs1.Fields("[CombinedRun]").value = [chkCombinedRun].value
TempRunID = rs1.Fields("[RunID]").value
rs1.Update
You can run a second query that uses the function
SELECT LAST_INSERT_ID();