asp.net insert query with to_date function - asp.net

I am inserting record in db using below mentioned query but it gives me error "Invalid number" so guide me.
string query1 = "insert into MNE.MNE_users(USER_ID,INSERTED_DATE) values ( '" + id + "',to_date('" + INSERTED_DATE.Text + "','DD/MM/YYYY') )";
Please guide me.

to_date() function solves my Problem

I think you should replace; 'yyyy-mm-dd + ' with 'yyyy-mm-dd'

Related

How to select from table where text box = formula with aggregates (Xojo+ SQLite)

I have a table with columns;
Fullname,
GroupNo,
Tdate,
Schedule,
Cramount,
Dramount,
Iamount.
I want to select those columns where textbox111.text is greater than formula SUM(Cramount)*26/(SUM(Dramount+Iamount)).
The SQL below give me syntax error, can someone help me please DATABASE IS SQLITE AND PROGRAMMING IN XOJO.
sql= "SELECT Fullname, GroupNo, Tdate, Schedule,( SUM(Cramount)*26)/SUM(Dramount+Iamount) AS ok FROM Trans WHERE Branchcode = '1210 - Loans'GROUP BY LoanID HAVING SUM(Cramount)*26/(SUM(Dramount+Iamount)) < '"TextBox111.text'""
There's a couple things wrong with your SQL string, you've got the single and double quote after the TextBox111.text around the wrong way, and you need to concatenate that control value with "+" as Xojo does not do string interpolation.
Try something like:
sql= "SELECT Fullname, GroupNo, Tdate, Schedule, (SUM(Cramount)*26)/SUM(Dramount+Iamount) AS ok FROM Trans WHERE Branchcode = '1210 - Loans' GROUP BY LoanID HAVING SUM(Cramount)*26/(SUM(Dramount+Iamount)) < '" + TextBox111.text + "'"
I'm pretty sure that SQLite supports using the alias for the agregate field in the having clause...
sql= "SELECT Fullname, GroupNo, Tdate, Schedule, (SUM(Cramount)*26)/SUM(Dramount+Iamount) AS ok FROM Trans WHERE Branchcode = '1210 - Loans' GROUP BY LoanID HAVING ok < '" + TextBox111.text + "'"
Your SQL also references two fields that you don't mention in as being in your table, Branchcode and LoanID, hopefully you just forgot to mention them.

Arithmetic overflow error converting expression to data type datetime. in asp.net

This is my code
sqlquery = "select * from Mytables where cname='" + name + "' and cast(cast('" + txtselectdate.Text + "' as char(8)) as datetime)";
Getting error as Arithmetic overflow error converting expression to data type datetime.
Please suggest some ideas
Use tihs
CONVERT(Datetime,txtselectdate.Text,110)
You can use any format instead of 110
or
you can simply pass the converted date in your query like this
DateTime.Parse(txtselectdate.Text)
then you do not need to cast it in query.
===========Update ========
select * from mytable where cname='" + name + "' and yourcolumnname=CONVERT(Datetime,'" + txtselectdate.Text + "',110)"
Add column name in your query by which this textbox value will match.
Hai all thanks for the help I got the answer it was a datatype problem in my database
I havent saved the data type as datetime so they occurs a clash in updating previously it was nvarchar

Can mix up parameter query in SQL statement in SQLite

Not sure If I can use this ?-operator in a Mix Up SQL statement for parameter Query. Is there any rule on this? Or I must use ? operator all the way.
Thank
Example:
var allUsers = await db.QueryAsync("Select * From Customer Where CompanyName =?" + " AND Name like '" + txtBxName.Text + "%'", Company);
It is possible to use parameters only for some strings, but that would be silly.
Appending % to a string can be done either in C#:
db.QueryAsync("SELECT ... ? ... Name LIKE ?", Company, txtBxName.Text + "%");
or in SQL:
db.QueryAsync("SELECT ... ? ... Name LIKE ? || '%'", Company, txtBxName.Text);

DropDownList value into Linq query where clause

I am facing following problem. I want a search field with a DropDowList next to it, where user can pick an item for which he wants to search. I have to make it with this LINQ code not just a SQL query.
Here's my code:
var Metadata = from m in db.Metadatas
join mm in db.Multimedias
on m.multimediaID equals mm.multimediaID
where (m. { Here would i have the selected value from the dropdownlist. } .ToString().Contains(textboxvalue) ||
mm. { Here would i have the selected value from the dropdownlist. } .ToString().Contains(textboxvalue))
&& mm.filetype.ToString().Contains(radiobuttonvalue)
I want to put something like: "Dropdownlist.selectedvalue" into the area { Here would i have the selected value from the dropdownlist. }
I hope you guys understand my idea and problem.
I am not sure why you are doing join on in your linq statement. That is not necessary if you Linq already knows about the relationship between the objects because there is a foreign key relationship setup in the database.
What you can do is this:
var Metedata = db.Metadatas;
switch(Dropdownlist.selectedvalue)
{
case "one":
Metadata = Metadata.Where(m => m.{selected value field}.Contains(textboxvalue));
break;
case "two":
Metadata = Metadata.Where(m => m.{selected value field}.Contains(textboxvalue));
break;
//More use cases
}
I am not sure what you will be selecting out of the list when you are done, but if it involves related objects (e.g. Multimedias) then you might want to look into DataLoadOptions (LinqToSQL) or .Include() (EntityFrameworks).
Just change your sql query:
if(supportgrp.SelectedItem.Text == "All")
sql ="SELECT * FROM QlyData where Date >='" + txtstartdate.Text + "' and Date<='" + txtenddate.Text + "'";
else
sql ="SELECT * FROM QlyData where Date >='" + txtstartdate.Text + "' and Date<='" + txtenddate.Text + "' and suppgrp = '" + supportgrp.Text + "'";

how to use scope_identity in sqlite

I have issue when i use scop_identity in sqlite it showing the error like near "select": syntax error...i write query like this
string txtSQLQuery = "insert into SerpTrak_Site (SiteName) values ('" + txturl.Text + "')select scope_identity();";
any wrong in this query please help me...
SQLite does not have a function by the name scope_identity
You are probably looking for 'SELECT last_insert_rowid()'
See also this question: Does SQLite support SCOPE_IDENTITY?
Missing a semicolon between the two queries.
string txtSQLQuery = "insert into SerpTrak_Site (SiteName)
values ('" + txturl.Text + "'); select scope_identity();";

Resources