I have the following SQLite statement:
"SELECT * FROM HISTORICALPICKS WHERE BETTYPE = " + betType.ToString().ToUpper() + " ORDER BY DATETIME ASC"
And betType.ToString().ToUpper() is the string "ATS"
For some reason I get the following error:
System.Data.SQLite.SQLiteException : SQL logic error or missing database
no such column: ATS
...which leaves me baffled. ATS is not a column. BETTYPE is the column. I want it to select rows that have "ATS" in the BETTYPE column.
My hunch is that something is wrong with the syntax. Here is a picture showing the table name and column name, along with a highlight of the value ATS:
You need single quotes around the value.
"SELECT * FROM HISTORICALPICKS WHERE BETTYPE = '" + betType.ToString().ToUpper() + "' ORDER BY DATETIME ASC"
Related
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.
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
I have a problem in this query.
I want to retrieve a data from a table by comparing with other column of table.
error is: An expression of non-boolean type specified in a context where a condition is expected, near ')'.
cmd.CommandText = "SELECT [news_id], [news_title] FROM [upload_news] WHERE [country]='" + DropDownList1.Text + "' AND (SELECT DISTINCT[authority] FROM [user_data] WHERE [authority]<>'trusted')";
The problem is that you are not doing any comparison with this condition:
AND (SELECT DISTINCT[authority] FROM [user_data] WHERE [authority]<>'trusted')
This is just returning a distinct list of items, and furthermore, is not being compared with something. Remember that statements on the WHERE clause are comparisons that results in a boolean value.
My problem is I am unable to insert values into sqlite3 using autohot key.
My code is:
MyName := name
myTel := telphonenumber
$sSQL := "insert into myTable Values ('" %MyName% "', " %myTel% ");"
and I also tried with ,
$sSQL := "insert into myTable Values ( ' " . MyName . " ', " . myTel . ");"
But neither of these works.
Any suggestion is appreciated..
I've not used AHK with SQLite before, but is it just the query you're having issues with? Try this (note the lack of the colon before the equals sign):
$sSQL = "insert into myTable Values ('%MyName%', '%myTel%');"
Your second attempt produces a query that is technically valid, but it would put a space either side of the name in the database ('John' would be ' John '). Also I'm guessing you don't really want to be using a numeric field in your database for a telephone number? If a number begins with 0 or is to large you could have issues. The version above will insert it as a string.
MyName := name
myTel := telphonenumber
$sSQL := "insert into myTable Values ('" MyName "', '" myTel "');"
I prefer to put the phone number also into apostrophe.
if you do not have a phone number then there is no error:
insert into myTable Values ('John', '' );
and as Gary said right: "If a number begins with 0 or ... issues."
the select of the telephone number 0177... will give you later 177...
better you also use a string for the phone number and not an number format.
create table myTable
(
name TEXT
phone TEXT
) ;
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();";