I get an error "ORA-00947: not enough values") inserting a record and can't see why! It seems to me I have the correct number of parameters:
string sQuery = "insert into EventLog (UserEventLogID, USERID, EVENTSEVERITYID, LOGTIME_TZ, USEREVENTTYPEID, USEREVENTMSG) " +
"values (0, :USERID, :EVENTSEVERITYID, cast(:LOGTIME_TZ as Timestamp(6) With Time Zone) at time zone '" + oLog.TimeZone + "'), " +
":EVENTTYPEID, :EVENTMSG) " +
" returning USEREVENTLOGID into :EventLogID";
oraCmd = new OracleCommand();
oraCmd.BindByName = true;
oraCmd.Parameters.Add("EVENTSEVERITYID", OracleDbType.Int16, 2, oLog.EventSeverityID, ParameterDirection.Input);
oraCmd.Parameters.Add("LOGTIME_TZ", OracleDbType.TimeStamp, 6, oLog.EventTimestamp, ParameterDirection.Input);
oraCmd.Parameters.Add("EVENTTYPEID", OracleDbType.Int16, 4, oLog.EventTypeID, ParameterDirection.Input);
oraCmd.Parameters.Add("EVENTMSG", OracleDbType.Varchar2, 300, oLog.EventMsg, ParameterDirection.Input);
oraCmd.Parameters.Add("USERID", OracleDbType.Varchar2, 50, oLog.UserID, ParameterDirection.Input);
outParam = new OracleParameter("EventLogID", OracleDbType.Decimal);
outParam.Direction = ParameterDirection.Output;
oraCmd.Parameters.Add(outParam);
the table has one more column "LGTIME" which is nullable so I did not include it in insert statement.
I see an extra ")" .
cast(:LOGTIME_TZ as Timestamp(6) With Time Zone) <----- at time zone '" + oLog.TimeZone + "')
Related
Below is the code where I compute date by subtracting TimeSpan from Today's Date.
DateTime todayDate = DateTime.Today;
TimeSpan minTS = new TimeSpan(6570, 0, 0, 0, 0);
TimeSpan maxTS = new TimeSpan(7300, 0, 0, 0, 0);
DateTime minDate = todayDate.Subtract(minTS);
DateTime maxDate = todayDate.Subtract(maxTS);
My Query is as below:
sql = "select AId,AName,DOB,Religion from Applicant,Creator as C where (C.CId = Applicant.CId and Approved = 'Approved' and Gender !='" + gend + "' and AId !=" + id + ") and (Applicant.Status = '" + status.Items[status.SelectedIndex].ToString() + "' and Applicant.DOB BETWEEN '" + maxDate + "' and '" + minDate + "')";
cmd = new SqlCommand(sql, con);
SqlDataAdapter da = new SqlDataAdapter(cmd); // use your existing SqlCommand here (don't use select *)
DataSet ds = new DataSet(); // create a DataSet object to hold you table(s)... this can contain more than 1 table
da.Fill(ds, "Comment");
This works fine for me. But when I change the values of TimeSpan to
TimeSpan(7300, 0, 0, 0, 0);
TimeSpan maxTS = new TimeSpan(9125, 0, 0, 0, 0);
I get the following error:
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
I hope there is no problem with the query, because the same query works fine for TimeSpan(6570,0,0,0,0) and TimeSpan(7300,0,0,0,0). It gives error when i change it to TimeSpan(7300,0,0,0,0) and TimeSpan(9125,0,0,0,0)
I am not getting where I am going wrong.
the date in excel is of the date time format and the selected date is also date time format but wots the problem
OleDbDataAdapter da1 = new OleDbDataAdapter("SELECT [ProjectId],[ProjectName],[ManagerID],[ManagerName],[AllocationStartDate],[AllocationEndDate],[horizontalshortname] FROM [" + getExcelSheetName + #"] where [horizontalshortname]="+ "'" + TextBox_Horizontal.Text + "'"
+ " AND [Isonsite]=" + "'" + DropDownList_Location.SelectedItem.Text + "'"
+ " AND [AllocationStartDate]>="+Calendar1.SelectedDate
+ " AND [AllocationEndDate]<="+Calendar2.SelectedDate
, conn);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
//if (ds.Tables[0] != null )
if (ds1.Tables[0].Rows.Count > 0)
{
GridView_Utilization_Search.Visible = true;
GridView_Utilization_Search.DataSource = ds1.Tables[0];
GridView_Utilization_Search.DataBind();
}
else
{
GridView_Utilization_Search.Visible = false;
}
It suppose there is chart to be appeared. But, it doesnt as there is problem regarding dbnull issue. This happen when either one of three select statement has no data.
Dim user As String = Session("NoMatrik")
Dim resultId As Object = Session("max")
Dim idQuery = "select max(resultid) as id from tblResult where result_nomatric = #matric and result_quiz_id = 1 UNION All " +
"select max(resultid) as id from tblResult where result_nomatric = #matric and result_quiz_id = 2 UNION All " +
"select max(resultid) as id from tblResult where result_nomatric = #matric and result_quiz_id = 3"
conn.Open()
Dim cmdGetId As New SqlCommand(idQuery, conn)
cmdGetId.Parameters.AddWithValue("#matric", user)
Dim maxIDs As SqlDataReader = cmdGetId.ExecuteReader
Dim IDs As String = ""
While maxIDs.Read
IDs += maxIDs("id").ToString() + ", "
End While
maxIDs.Close()
IDs = IDs.Substring(0, IDs.Length - 2)
Dim cmdString = "Select tblResult.result_quiz_id as Quiz,count(TblAnswer.AnswerType) as answerCount , TblAnswer.AnswerType " +
"from TblResultDetail inner join TblAnswer on TblResultDetail.ResultDetail_Answer_Id = TblAnswer.AnswerId " +
"inner join tblResult on tblResult.resultid = TblResultDetail.ResultDetail_Result_Id " +
"where TblResultDetail.ResultDetail_Result_Id in (" + IDs + ") " +
"group by TblAnswer.AnswerType, tblResult.result_quiz_id order by TblAnswer.AnswerType"
Dim cmd As New SqlCommand(cmdString, conn)
If IsDBNull(resultId) Then
Label1.Visible = True
chrtResult.Visible = False
Else
Dim dr1 As SqlDataReader
dr1 = cmd.ExecuteReader
While dr1.Read()
Dim tempArr(0) As Double
Dim count As Double = dr1("answerCount")
tempArr(0) = count
Dim Type As String = dr1("AnswerType").ToString()
Dim level As Integer = dr1("Quiz")
chrtResult.Series(Type).Points(level - 1).YValues = tempArr
End While
End If
conn.Close()
End If
End Sub
an error, Incorrect syntax near '(' appear at line dr1 = cmd.ExecuteReader. So , how I want to fix this error?
Update your first query to exclude any Null values using a HAVING clause like so:
Dim idQuery = "select max(resultid) as id from tblResult " +
"where result_nomatric = #matric and result_quiz_id = 1 " +
"having max(resultid) is not null " +
"UNION All " +
"select max(resultid) as id from tblResult " +
"where result_nomatric = #matric and result_quiz_id = 2 " +
"having max(resultid) is not null " +
"UNION All " +
"select max(resultid) as id from tblResult " +
"where result_nomatric = #matric and result_quiz_id = 3 " +
"having max(resultid) is not null"
The having max(resultid) is not null will exclude any nulls in your UNION ALL.
If there are no IDs returned, you simply need to do a check on this before you execute your next block of code and do as #DmitriE suggests with the adding of quotes. Reorganise it to look like:
While maxIDs.Read
IDs += "'" + maxIDs("id").ToString() + "', "
End While
If IDs = "" Then
Label1.Visible = True
chrtResult.Visible = False
Else
IDs = IDs.Substring(0, IDs.Length - 2)
Dim cmdString = "Select ....."
Dim dr1 As SqlDataReader
dr1 = cmd.ExecuteReader
While dr1.Read()
' YOUR WHILE LOOP CODE HERE'
End While
End If
This should be
While maxIDs.Read
IDs += "'" + maxIDs("id").ToString() + "', "
End While
and then you need to remove last single quote.
in clause should follow this format: where x.id in ('id1', 'id2', 'idN')
I have date in string format like "14-12-2012". After converting the date from string to date it is giving like this "#12/14/2012#"
Then I am trying to save date in database it is giving error.
Dim queryString As String = "UPDATE [ARIBA_CUST_ADMIN] SET [CUST_CRED_ID] = '" + eCustomer.CUST_CRED_ID + "',[CUST_NAME] = '" + eCustomer.CUST_NAME + "',[STREET1] = '" + eCustomer.STREET1 + "',[STREET2] = '" + eCustomer.STREET2 + "',[CITY] = '" + eCustomer.CITY + "',[State] = '" + eCustomer.STATE + "',[POSTAL_CD] = '" + eCustomer.POSTAL_CD + "',[COUNTRY] = '" + eCustomer.COUNTRY + "',[CUST_CRED_DOMAIN] = '" + eCustomer.CUST_CRED_DOMAIN + "',[SUBCHARGE] = '" + eCustomer.SUBCHARGE + "',[TAX_AT_LINE] = '" + eCustomer.TAX_AT_LINE + "',[PO_FLIP] = '" + eCustomer.PO_FLIP + "',[STATUS] = '" + eCustomer.STATUS + "',[CONFIMRATIONS] = '" + eCustomer.CONFIMRATIONS + "',[SHOP_NOTICES] = '" + eCustomer.SHOP_NOTICES + "',[INVOICE_TYPE] = '" + eCustomer.INVOICE_TYPE + "',[EFFECTIVE_DATE] = " + eCustomer.EFFECTIVE_DATE + ",[DISTRIBUTION_XML] = '" + eCustomer.DISTRIBUTION_XML + "' WHERE [CUST_ID] = " + eCustomer.CUST_ID
Dim dateString, format As String
Dim result As Date
Dim provider As Globalization.CultureInfo = Globalization.CultureInfo.InvariantCulture
' Parse date and time with custom specifier.
dateString = "20121216"
format = "yyyyMMdd"
result = Date.ParseExact(dateString, format, provider)
This will output the date in whatever format you specify in the format variable.
For the date format you want you'd use:
format = "dd-MM-yyyy"
You should use a parameterised query then you don't need to worry about the specific format, you just pass a date as the parameter (Assuming your DB column is a date type - it should be if it isn't):
Something along these lines
Dim d as Date= new Date(2012, 12, 3)'or ParseExact from a string in a known format
Dim sql As String = "INSERT INTO foo (DateValue) VALUES (#DateValue)"
Using cn As New SqlConnection("Your connection string here"), _
cmd As New SqlCommand(sql, cn)
cmd.Parameters.Add("#DateValue", SqlDbTypes.Date).Value = d
cmd.ExecuteNonQuery
End Using
Have a look at this question for more info
And i am back again.
I have asked a similair question before, but even with the help of the previous anwser and trying it with questionmarks or instead of Add i've tried AddWithValue i didn't have any luck.
I tried to change the txt_Naam to txt_Naam.Text, nothing.
Also putting [] around the columnnames, no luck.
It keeps giving me this "Syntax error in INSERT INTO statement.".
This time i got nowhere with the code below.
Probably something small, but i can't figure it out. (Again...)
protected void btn_final_Click(object sender, EventArgs e)
{
string fact_adres = txt_Naam.Text + "," + txt_Anaam.Text + "," + txt_Adres.Text + "," + txt_Toevoeg.Text + "," + txt_Pcode.Text + "," + txt_Plaats.Text + "," + txt_Email.Text ;
string fact_adres1 = txt_Naam1.Text + "," + txt_Anaam1.Text + "," + txt_Adres1.Text + "," + txt_Toevoeg1.Text + "," + txt_Pcode1.Text + "," + txt_Plaats1.Text + "," + txt_Email1.Text;
string a = "1";
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; "
+ "Data Source=|DataDirectory|webwinkel.accdb";
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO Order (factuur_adres_id, verzend_adres_id, totaalprijs) VALUES (?, ?, ?);";
cmd.Parameters.Add("#factuur_adres", OleDbType.VarChar, 125).Value = fact_adres;
cmd.Parameters.Add("#verzend_adres", OleDbType.VarChar, 125).Value = fact_adres1;
cmd.Parameters.Add("#totaal_prijs", OleDbType.VarChar, 7).Value = a;
try
{
conn.Open();
OleDbDataReader reader = cmd.ExecuteReader();
reader.Close();
}
catch (Exception exc)
{
Label1.Text = exc.Message;
}
finally
{
conn.Close();
Session["Winkelwagen"] = null;
}
}
You command text should be
cmd.CommandText = "INSERT INTO Order (factuur_adres_id, verzend_adres_id, totaalprijs) VALUES (#factuur_adres,#verzend_adres, #totaal_prijs)";
Updated answer:
run your code with setting parameters, directly pass the value and check that it works or not
cmd.CommandText = "INSERT INTO Order (factuur_adres_id, verzend_adres_id, totaalprijs) VALUES ('abc','def','adf')";
When you are inserting don't you have to use
cmd.ExecuteNonQuery()
Instead of cmd.ExecuteReader() ??