Update and insert MySQL using Classic ASP - mysql

I'm trying to update on a database in MySQL using Classic ASP, but it's not working. Could someone tell me what might be wrong in my code?
IDCliSession = Session("usuarioident")
if IDCliSession <> "" then
IDCliSession = IDCliSession
else
IDCliSession = 0
end if
set cli = conexao.execute("SELECT * FROM clientes WHERE id_cliente = "& IDCliSession &"")
senha_S = request.form("senha")
senha_C = request.form("confsenha")
senha = request.form("confsenha")
if senha1 & "" <> "" or senha2 & "" <> "" then
if senha_S <> senha_C then
response.redirect "Registro.asp?msg=A Senha e a Confirmação de Senha não são iguais. Por favor, preencha novamente!"
end if
end if
loja = "1062"
tipoPe = request.Form("tipo")
email = request.Form("email")
fone1 = request.Form("fonefixo")
fone2 = request.Form("fonecel")
cep = request.Form("cep")
tipo_residencia = request.Form("tipo_residencia")
endereco = request.Form("endereco")
numero = request.Form("numero")
bairro = request.Form("bairro")
complemento = request.Form("complemento")
cidade = request.Form("cidade")
fk_estado = request.Form("estado")
fk_pais = request.Form("pais")
data = Date()
if request.Form("newsletter") = "1" then
newsletter = 1
else
newsletter = 0
end if
conhecimento = request.Form("tipo")
modalidade = request.Form("modalidade")
modalidade_ativa = "0"
comentarios = ""
if not cli.eof then
query = "SELECT * FROM clientes WHERE email='"& Session("mail") &"'"
Set rsCliente = Server.CreateObject("ADODB.RecordSet")
rsCliente.Open query, conexao, 2, 3
rsCliente("tipo") = tipoPe
rsCliente("email") = email
rsCliente("senha") = senha
rsCliente("fone1") = fone1
rsCliente("fone2") = fone2
rsCliente("cep") = cep
rsCliente("tipo_residencia") = tipo_residencia
rsCliente("endereco") =endereco
rsCliente("numero") = numero
rsCliente("fk_pais") = fk_pais
rsCliente("newsletter") = newsletter
rsCliente("conhecimento") = conhecimento
rsCliente("modalidade") = modalidade
rsCliente.Update
rsCliente.Close
Set rsCliente = Nothing
end if

Besides inefficiency of the method you chooses, could you also look if the variables you attempt to update to actually not conflicting with database indexes or primary/foreign keys in database?
If you attempt to pass empty string into fields which set as not null it will abort procedure.
For example field tipoPe = request.Form("tipo") or email = request.Form("email") could be a mandatory in your table or set as unique. I do not see any validation for that...
Best solution would be use of a store procedure which would return you a string in case of failure or successes.
And also what are you attempt to validate her:
senha_S = request.form("senha")
senha_C = request.form("confsenha")
senha = request.form("confsenha")
if **senha1** & "" <> "" or **senha2** & "" <> "" then
if senha_S <> senha_C then
where does senha1 and senha2 comes from?
For password verification following would be more then sufficient:
if senha_S <> senha_C and len(senha_S)<8 then
using len(senha_S)<8 you also enforcing minimal lenght of the password.
Also I would recommend following changes in your redirect:
response.redirect "Registro.asp?msg='A Senha e a Confirmação de Senha não são iguais. Por favor, preencha novamente!'"
otherwise you may on your redirect page get only small portion of your message, like only first letter A.

Related

Best way to convert a VBA script to google Apps script on google sheets

i'm working on a script that allows me to connect to an external API and use urlfetchapp to fetchdata, but for some objects, i have to create a dictionary of object to display the right value at the right cell, since i'm a beginner, i didn't succeed to convert this part of the script to a google apps script code, any help would be welcome :
Set TableauTaxesInclusion = New Dictionary
'Récupération des infos de taxe incluses ou pas
If Not IsEmpty(Produit("lecTaxInclusionInformationList")) Then
For t = 1 To Produit("lecTaxInclusionInformationList").Count 'Parcours des taxes incluses
Set UneTaxe = Produit("lecTaxInclusionInformationList").Item(t)
If Not IsEmpty(UneTaxe("lecTaxCode")) And Not IsNull(UneTaxe("lecTaxCode")) Then
TableauTaxesInclusion.Add UneTaxe("lecTaxCode")("code"), IIf(Not IsEmpty(UneTaxe("lecIsTaxIncludedInPrice")) And Not IsNull(UneTaxe("lecIsTaxIncludedInPrice")) And UneTaxe("lecIsTaxIncludedInPrice") = True, "X", "")
'Debug.Print UneTaxe("lecTaxCode")("code")
End If
Next
End If
If Not IsEmpty(Produit("dutyFeeTaxInformationList")) Then
Set TableauTaxes = New Dictionary
For t = 1 To Produit("dutyFeeTaxInformationList").Count
Set Taxe = Produit("dutyFeeTaxInformationList")(t)
If Not (IsNull(Taxe("dutyFeeTaxTypeCode"))) Then
If TableauTaxes.Exists(Taxe("dutyFeeTaxTypeCode")("code")) Then
TableauTaxes(Taxe("dutyFeeTaxTypeCode")("code")) = 1 + TableauTaxes(Taxe("dutyFeeTaxTypeCode")("code"))
Else
TableauTaxes.Add Taxe("dutyFeeTaxTypeCode")("code"), 1
End If
End If
Next
For t = 1 To Produit("dutyFeeTaxInformationList").Count 'Parcours des taxes
Set Taxe = Produit("dutyFeeTaxInformationList")(t)
If Not (IsNull(Taxe("dutyFeeTaxTypeCode"))) Then
If Left(Taxe("dutyFeeTaxTypeCode")("label"), 3) = "TVA" Or Left(Taxe("dutyFeeTaxTypeCode")("label"), 3) = "VAT" Then
If tva = True Then
TableauProduits(ligne, numColCheckTVA) = "X"
If TableauProduits(ligne, numColTVA) = Taxe("dutyFeeTaxTypeCode")("label") Then
If TableauProduits(ligne, numColValTVA) = "" Then
If (Taxe("dutyFeeTaxList").Count > 0) Then
TableauProduits(ligne, numColValTVA) = Taxe("dutyFeeTaxList")(1)("dutyFeeTaxRateNumber")
End If
End If
Else
TableauProduits(ligne, numColCheckTVA) = "PB"
End If
Else
TableauProduits(ligne, numColTVA) = Taxe("dutyFeeTaxTypeCode")("label")
If (Taxe("dutyFeeTaxList").Count > 0) Then
TableauProduits(ligne, numColValTVA) = Taxe("dutyFeeTaxList")(1)("dutyFeeTaxRateNumber")
If (Taxe("dutyFeeTaxList").Count > 1) Then
TableauProduits(ligne, numColCheckTVA) = "PB"
End If
End If
End If
tva = True
actually i'm just able to write the first part :
var tableautaxinclusion = [];
if (produit.leclercTaxInclusionInformationList != 0){
for(inc = 1 ; inc < produit.leclercTaxInclusionInformationList.length ; inc++ )
set Taxinc = produit.leclercTaxInclusionInformationList[inc]
}
if (Taxinc.leclercTaxCode != null & Taxinc.leclercTaxCode != 0 ){
tableataxinclusion = Taxinc
}

about field update using function with case

I'm trying to update some field value depending two string field using a function with If and Case, function below:
Private Function checkDATI(tipotransazione As String, tipovendita As String) As String
Dim r As String
r = ""
If tipotransazione = "VENDITA" Then
Select Case tipovendita
Case "ARMI"
If Me.txtMatricola = "" Then r = "Matricola"
If Me.txtModello = "" Then r = "Modello"
If Me.txtCalibro = "" Then r = "Calibro"
If Me.txtTipoArma = "" Then r = "Tipo Arma"
If Me.txtFabrica = "" Then r = "Fabbrica"
Case "VENDITA ARMI/MUNIZIONI"
Case "MUNIZIONI"
End Select
End If
If tipotransazione = "ACQUISTO" Then
Select Case tipovendita
Case "ARMI"
If Me.txtMatricola = "" Then r = "Matricola"
If Me.txtModello = "" Then r = "Modello"
If Me.txtCalibro = "" Then r = "Calibro"
If Me.txtTipoArma = "" Then r = "Tipo Arma"
If Me.txtFabrica = "" Then r = "Fabbrica"
Case "VENDITA ARMI/MUNIZIONI"
Case "MUNIZIONI"
End Select
End If
checkDATI = r
End Function
And then when I call this function in a command button event as:
MsgBox (checkDATI(Me.CausaleMov, Me.txt_tipomov))
It's not updating that field. What is wrong?
When you say:
If Me.txtMatricola = "" Then r = "Matricola"
What you are doing is assigning the value: "Matricola" to the variable:r. Instead what I think you want is this:
If Me.txtMatricola = "" Then Me.txtMatricola = "Matricola"
This actually sets the value of the field: txtMatricola to "Matricola". This goes for all of the fields that are in your Case statements.

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..

multiple if statements missing data

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