"ORA-00917: missing comma" & vbLf - oracle

Below is my query which is created in .Net code for insertion in oracle table. I found other related articles but they are different and not answering this. I was creating below query using a datatable.
`Public Sub UpdateOracleRecordset(dtTable As DataTable)
Dim sql As String = String.Empty
Dim i As Integer = 0
sql = "insert into " + dtTable.TableName + "("
For Each dc As DataColumn In dtTable.Columns
sql = sql + dc.ToString() + ","
Next
sql = sql.TrimEnd(",") + ")" + " select "
Dim rowVal As String = String.Empty
For Each dtRow As DataRow In dtTable.Rows
For Each dc As DataColumn In dtTable.Columns
rowVal = rowVal + dtRow(dc).ToString() + ","
Next
rowVal = rowVal.TrimEnd(",")
Next
sql = sql + rowVal
ExecuteSQL(sql)
End Sub`
"insert into CS_INV(LOANNO,CASENUMBER,INQ_TYPE,FUP_REASON,FUP_DATE,FUP_PROM,USERID,DATA_DAT,UNIT) values ( 5735985,103550709,399,58,9/24/2018 1:37:01 AM,9/25/2018 12:00:00 AM,Anurag,9/24/2018 1:37:08 AM,1 ) "

Wenfried is right and I used prepared statements which helped to resolve the issue
Dim conn As New OracleConnection(oradb)
conn.Open()
Dim sql As String = String.Empty
Dim sqlValues As String = String.Empty
Dim i As Integer = 0
sql = "insert into " + dtTable.TableName + "("
For Each dc As DataColumn In dtTable.Columns
sql = sql + dc.ToString() + ","
sqlValues = sqlValues + ":" + dc.ToString() + ","
Next
sql = sql.TrimEnd(",") + ")" + " values ( " + sqlValues.TrimEnd(",") + ")"
Dim commandText = sql
Dim Command As New OracleCommand(sql, conn)
For Each dtRow As DataRow In dtTable.Rows
For Each dc As DataColumn In dtTable.Columns
Command.Parameters.Add(New OracleParameter(dc.ToString(), dtRow(dc)))
Next
Next
Command.ExecuteNonQuery()
conn.Close()

Related

Getting ORA-01036: illegal variable name/number error on select query vb.net code

I am getting below error while executing a select statement on vb.net for oracle. I am trying to pass account number as a parameter to the select statement . Below is the SQL statement
Dim strSearchSQL As String
strSearchSQL = "SELECT A.ACCT_GRP_CD, A.AVG_METH_CD , B.AVG_METH_DSCR, A.ACCT_GRP_DSCR, A.COST_POOL_CD, A.ABC_MULT_NUM, A.INTRM_METH_CD, A.RATE_POOL_RPT_CD FROM GL_ACCT_GRP_TB A, GL_AVG_METH_TB B WHERE A.AVG_METH_CD = B.AVG_METH_CD"
If Not AccountGroup = "" Then
strSearchSQL = strSearchSQL & " AND ACCT_GRP_CD LIKE '%{: AccountGroup}%' "
End If
If Not OrderBy = "" And Not OrderAs = "" Then
strSearchSQL = strSearchSQL & " ORDER BY " & OrderBy & " " & OrderAs
Else
strSearchSQL = strSearchSQL & " ORDER BY ACCT_GRP_CD XYZ "
End If
Dim cmd As New OracleCommand
cmd.CommandText = strSearchSQL
cmd.CommandType = CommandType.Text
cmd.Connection = Connection.GetConnection
cmd.Parameters.Clear()
Dim Param1 As OracleParameter = New OracleParameter("AccountGroup", OracleType.Char, 500)
Param1.Direction = ParameterDirection.Input
Param1.Value = AccountGroup.Trim
cmd.Parameters.Add(Param1)
and Below is the error that I am getting
Error : ORA-01036: illegal variable name/number
Please help me to identify where exactly I am making mistake
You only want to add the AccountGroup parameter if it is present in the SQL:
cmd.Parameters.Clear()
If Not AccountGroup = "" Then
Dim Param1 As OracleParameter = New OracleParameter("AccountGroup", OracleType.Char, 500)
Param1.Direction = ParameterDirection.Input
Param1.Value = AccountGroup.Trim
cmd.Parameters.Add(Param1)
End If
Try it like this:
Dim strSearchSQL As String
Dim cmd As New OracleCommand
cmd.CommandType = CommandType.Text
cmd.Connection = Connection.GetConnection
strSearchSQL = "SELECT A.ACCT_GRP_CD, A.AVG_METH_CD , B.AVG_METH_DSCR, A.ACCT_GRP_DSCR, A.COST_POOL_CD, A.ABC_MULT_NUM, A.INTRM_METH_CD, A.RATE_POOL_RPT_CD "
strSearchSQL = strSearchSQL & " FROM GL_ACCT_GRP_TB A"
strSearchSQL = strSearchSQL & " JOIN GL_AVG_METH_TB B ON A.AVG_METH_CD = B.AVG_METH_CD " ' -> Modern join syntax
If Not AccountGroup = "" Then
strSearchSQL = strSearchSQL & " WHERE ACCT_GRP_CD LIKE :AccountGroup "
Dim Param1 As OracleParameter = New OracleParameter("AccountGroup", OracleType.VarChar, 500)
Param1.Direction = ParameterDirection.Input
' ParameterDirection.Input and OracleType.VarChar are default, you could skip them
Param1.Value = "%{" & AccountGroup.Trim & "}%"
cmd.Parameters.Add(Param1)
End If
If Not OrderBy = "" And Not OrderAs = "" Then
strSearchSQL = strSearchSQL & " ORDER BY " & OrderBy & " " & OrderAs
Else
strSearchSQL = strSearchSQL & " ORDER BY ACCT_GRP_CD XYZ "
End If
cmd.CommandText = strSearchSQL

Adding multiple times together

I'm trying to add some data that is pulled from a database in the format of HH:MM:SS I'm trying to get them to add together so if we have 00:00:05 then 00:00:10 so we have 00:00:15
I have attempted both TimeSpan, DateTime but I get the following error:
Microsoft VBScript runtime error '800a01a8'
Object required: 'TimeSpan'
Script Location, line 157
This is the code:
While Not objRS.EOF
activecalls = activecalls + objRS("talkingagents")
callswaiting = callswaiting + objRS("callswaiting")
averagetalkingtime = averagetalkingtime + objRS("convavgtalkduration")
totalqueue = totalqueue + 1
totalcalls = totalcalls + objRS("totalcalls")
newWait = objRS("convavgwaitduration")
TimeSpan t1 = TimeSpan.Parse(newWait)
TimeString FormattedDate = t1.Add(FormattedDate)
timeString = timeString.Add(t1).ToString("dd\.hh\:mm\:ss")
Not clear with your code but this probably what you are looking for.
t1 = CDate("00:00:05")
t2 = CDate("00:00:10")
t3 = t1 + t2
MsgBox Right("00" & Hour(t3), 2) + ":" + Right("00" & Minute(t3), 2) + ":" + Right("00" & Second(t3), 2)

How to check listindex of combo in vb6?

I load values of combo boxes here but I don't want to set ListIndex property to -1.
Private Sub Form_Load()
OPENCON
RES.Open "DIVISION", CON, adOpenDynamic, adLockOptimistic, adCmdTable
If RES.RecordCount > 0 Then
RES.MoveFirst
For i = 0 To RES.RecordCount - 1
CmbDiv.AddItem RES.Fields("DIV").Value
CmbDiv.ItemData(CmbDiv.NewIndex) = RES.Fields("DIVID").Value
RES.MoveNext
Next
End If
RES.Open "HNM", CON, adOpenDynamic, adLockOptimistic, adCmdTable
If RES.RecordCount > 0 Then
RES.MoveFirst
For i = 0 To RES.RecordCount - 1
CmbHouse.AddItem Trim(RES.Fields("HOUSE").Value)
CmbHouse.ItemData(CmbHouse.NewIndex) = RES.Fields("HID").Value
RES.MoveNext
Next
End If
End Sub
This is the code I used to modify record.
Private Sub CmdSave_Click()
sql = "UPDATE STUDENT_RECORD_DATABASE SET "
sql = sql + "ROLLNO= " & Val(CmbRNO) & ","
sql = sql + "DIVID='" & Val(CmbDiv.ItemData(CmbDiv.ListIndex)) & "',"
sql = sql + "HID=" & Val(CmbHouse.ItemData(CmbHouse.ListIndex)) & " "
sql = sql + "WHERE ROLLNO= " & Val(CmbRNO) & ""
Set RES = CON.Execute(sql)
End Sub
While running the code if I modify both division and house then it's ok
but when I let any one value of them(doesn't modify value) it shows error on the 3rd and 4th lines of CmdSave_Click:
Invalid Property array value
after loading your data into the combobox, set the listindex to 0
Combo1.ListIndex = 0
it would be better though to check if listindex is -1, and if it is -1, then don't do the action, or give the user a warning that he should select something from the combobox

can't retrieve dropdownlist.selectedvalue on Page Load?

i have a drop down box , it has value that is retrieve from datasqlsource, however i want to get the count value on page load but it seem that it did not count
'Dim adapter As New SqlDataAdapter
'Dim ds As New DataSet
'Dim connectionString = ConfigurationManager.ConnectionStrings("myProject").ConnectionString
'Dim myConn As New SqlConnection(connectionString)
'Dim cmd = "SELECT * FROM Group Where groupID='" & DropDownList1.SelectedValue & "' AND customerID='" & Session("customerID") & "'"
'Try
' myConn5.Open()
' Dim myCmd5 As New SqlCommand(cmd5, myConn5)
' adapter.SelectCommand = myCmd5
' adapter.Fill(ds, "Group")
' ' txtQuan.Text = adapter.SelectCommand.ExecuteScalar().ToString()
' adapter.Dispose()
' myCmd5.Dispose()
' ' txtQuan.Text = ds.Tables(0).Rows.Count
' If ds.Tables(0).Rows.Count >= 10 Then
' lblNoPpl.Text = "The group is full"
' Else
' Dim numLefts As Integer = 10 - ds.Tables(0).Rows.Count
' lblNoPpl.Text = numLefts.ToString() + "space left"
'Catch ex As Exception
' MsgBox("Can not open connection ! ")
'End Try
if you use cmd.ExcuteScalar() method retrieve a count,the sql should be
SELECT COUNT(*) FROM Group Where groupID='" & DropDownList1.SelectedValue & "' AND customerID='" & Session("customerID") & "'"

INSERT IN FOXPRO

I HAVE iNSERT TO TABLE AG_MAS IN fOXPRO FOLLOW:
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection connect = new OleDbConnection("Provider=VFPOLEDB.1;Data Source=pl_prov.dbf");
try
{
connect.Open();
string strSQL = "insert into ag_mas";
strSQL += "(ag_code,ag_level,ag_group,ag_rcode,ag_status,";
strSQL += "ag_type,ag_gender,ag_lname,ag_fname,ag_add1,";
strSQL += "ag_add2,ag_add3,ag_add4,ag_class,ag_vouch,";
strSQL += "pl_prov,pl_zone,ag_jdate,ag_ddate,ag_dbrith,ag_bank ,";
strSQL += "ag_bankno,ag_telno,ag_faxno,ag_email,ag_ppay,";
strSQL += "ag_contno,ag_dcont,ag_ladate,ag_lpolno,ag_lendno,";
strSQL += "ag_comm,ag_maxcom,ag_orcomm,ag_om1com,ag_om2com,";
strSQL += "ag_om3com,ag_oy1com, ag_oy2com,ag_oy3com,ag_network)";
strSQL += "values (";
strSQL += "'" + textBox1.Text + "',";//ag_code
strSQL += "'" + textBox2.Text + "',";//ag_level
strSQL += "'" + textBox3.Text + "',";//ag_group
strSQL += "' ' ,"; //ag_rcode
strSQL += "'" + textBox4.Text + "',";//ag_status
strSQL += "'" + textBox22.Text + "',";//ag_type
strSQL += "'" + textBox5.Text + "',";//ag_gender
strSQL += "'" + textBox6.Text + "',";//ag_lname
strSQL += "'" + textBox7.Text + "',";//ag_fname
strSQL += "'" + textBox8.Text + "',";//ag_add1
strSQL += "'" + textBox9.Text + "',";//ag_add2
strSQL += "'" + comboBox1.Text + "',";//ag_add3
strSQL += "' ' ,"; //ag_add4
strSQL += "'" + textBox10.Text + "',";//ag_class
strSQL += "'" + textBox11.Text + "',";//ag_vouch
strSQL += "'" + comboBox1.SelectedValue + "',";//pl_prov
strSQL += "' ' ,"; //pl_zone
strSQL += "'" + textBox12.Text + "',"; //ag_jdate
strSQL += "'1987/10/10',"; //ag_ddate
strSQL += "'1987/10/10',"; //ag_dbirth
strSQL += "' ' ,"; //ag_bank
strSQL += "' ' ,"; //ag_bankno
strSQL += "' ' ,"; //ag_telno
strSQL += "' ' ,"; //ag_faxno
strSQL += "' ' ,"; //ag_email
strSQL += "'" + textBox13.Text + "',"; //ag_ppay
strSQL += "'" + textBox15.Text + "',";//ag_contno
strSQL += "'" + textBox14.Text + "',";//ag_dcont
strSQL += "'1987/10/10', "; //ag_ladate
strSQL += "' ' ,"; //ag_lpopno
strSQL += "' ' ,"; //ag_lendno
strSQL += "0,"; //ag_comm
strSQL += "0,"; //ag_maxcom
strSQL += "0,"; //ag_orcomm
strSQL += "0,"; //ag_om1com
strSQL += "0,"; //ag_om2com
strSQL += "0,"; //ag_om3comm
strSQL += "0,"; //ag_oy1com
strSQL += "0,"; //ag_oy2Xcom
strSQL += "0,"; //ag_oy3com
strSQL += "' ')"; //ag_network
OleDbCommand cmd = new OleDbCommand(strSQL, connect);
cmd.ExecuteNonQuery();
}
catch(Exception err)
{
MessageBox.Show(err.Message);
}
}
}
BUT I CAN'T INSERT. BECAUSE ERROR "DATA MISS MATCH" PLEASE HELP ME.
I agree with Frank on the issue with dates... It could also be trying to do a text into a numeric field (or any other such swapping).
However, a bigger issue might be if/when you get into using a true SQL database such as Oracle, SQL-Server, MySQL, etc... (not that I have anything against VFP and have been programming with Foxpro since '85) But doing SQL statements like you have, especially in any web-based system would leave you wide-open to SQL-injection attacks.
Its better to use parameterized query/insert/update/deletes.
A Data Type Mismatch error occurs when you try to insert an inappropriate data type into a field. For example, if you try to store a string into an integer field.
At first glance I think the format of your dates is the problem. Change "'1987/10/10'," to "{^1987-10-10},".
If changing the dates does not correct the problem, it would be helpful if you could show me the result of the strSQL variable and structure of the ag_mas table.
I agree with Frank in regards to a solution and I believe that DRapp has a valid point about how you are going about your insert statement. To add to DRapp’s suggestion, I’d like to point out that you could use LINQ to VFP to handle writing all your sql commands.

Resources