Below I provide my database schema, the database data currently inserted (which is only one record), and the code I am running. It is a very simple setup, but instead of returning the one record in the database, it returns nothing. Anyone have any idea why? I am on my wit's end here...
Table: Subcontractor
Columns: listed below in (name type) format.
ID guid,
BusinessName varchar(50),
Address varchar(200),
City varchar(50),
State varchar(50),
ZipCode varchar(50),
Contact varchar(50),
Phone varchar(50),
Fax varchar(50),
Email varchar(200),
GLOPolicy bit,
GLOLimit bigint,
GLOExpiration datetime,
ALPolicy bit,
ALLimit bigint,
ALExpiration datetime,
WCPolicy bit,
WCLimit bigint,
WCExpiration datetime,
ULPolicy bit,
ULLimit bigint,
ULExpiration datetime,
Notes varchar(15000)
=====
I have one record in my database, as follows.
ID "7b143c19-ad66-46ad-b587-db0bee98cf1e"
BusinessName "1"
Address "1"
City "1"
State "1"
ZipCode "1"
Contact NULL
Phone NULL
Fax NULL
Email NULL
GLOPolicy False (0)
GLOLimit NULL
GLOExpiration NULL
ALPolicy False (0)
ALLimit NULL
ALExpiration NULL
WCPolicy False (0)
WCLimit NULL
WCExpiration NULL
ULPolicy False (0)
ULLimit NULL
ULExpiration NULL
Notes NULL
===== *I am attempting the following query, and it returns nothing, when it should obviously return the only record, shown above.*
String ID = "7b143c19-ad66-46ad-b587-db0bee98cf1e";
DataTable dt = sqliteQuery.selectFromDatabase("*", "WHERE ID = '" + ID + "'");
And the code for the above method is...
public DataTable selectFromDatabase(String column, String filter)
{
string SQL = "SELECT " + column + " FROM SUBCONTRACTOR " + filter;
SQLiteCommand cmd = new SQLiteCommand(SQL);
cmd.Connection = connecti开发者_运维百科on;
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
DataSet ds = new DataSet();
try
{
da.Fill(ds);
DataTable dt = ds.Tables[0];
return dt;
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
return null;
}
finally
{
cmd.Dispose();
connection.Close();
}
}
It looks like SqLite does not support a GUID type natively. It's supported by wrappers and plugins but I think that you're experiencing some impedance between the way the type is used. You are probably better off changing it to a TEXT type. Your predicate will then work.
EDIT
To create a new GUID value to insert into the row as a pkey just do:
Guid.NewGuid().ToString();
In addition I found the following info:
GUID is not(!) a native SQLite-datatype, but an addon provided by Robert's wrapper. In the connection string you can specify "BinaryGUID=Yes|No", with Yes as default. When "BinaryGUID=Yes" the GUID is stored taking 16 bytes of storage. Now it depends whether "SQLite Expert" recognises the datatype GUID. If so, you should look at its documentation how it is handled. If not, it is probably treated as text (likely with invalid character data). You will have this trouble again when you change your SQLite editor or wrapper.
When "BinaryGUID=No" the GUID is stored as text taking 32-38 bytes (I don't know whether the minus-signs and braces {} are stored, you have to test). When storage is not a large problem, I would recommend to use this form. You then should have no problems with whatsover wrapper or DB editor you use and save a lot of time and trouble.
There seems to be an issue with the type itself.
精彩评论