I recently learned about SQLite. After reading some documents, I wrote an example. It may be useful for beginners of SQLite or learning to insert images into the database. I will release the source code for reference. You are also welcome to make suggestions.
It contains common SQL operations, including addition, deletion, modification, and query. It is also described in the example that SQL statements of sqsag use parameters, which can be @ or $.
1. Demo using:
String ext = system. Io. Path. getextension (myfile. filename). tolower ();
If (EXT = ". jpg "| ext = ". BMP "| ext = ". JPEG "| ext = ". GIF "| ext = ". PNG "| ext = ". tiff "| ext = ". JPEG ")
{
String SQL = "insert into files (ID, [filename], filetype, filelength, filebyte, uploaddate, downloadcount, remark) values (@ ID, @ filename, @ filetype, @ filelength, @ filebyte, @ uploaddate, @ downloadcount, @ remark )";
Sqlitecommand cmd = new sqlitecommand (SQL, new sqliteconnection (datasouce ));
Cmd. Parameters. addwithvalue ("@ ID", guid. newguid (). tostring ());
Cmd. Parameters. addwithvalue ("@ FILENAME", myfile. filename );
Cmd. Parameters. addwithvalue ("@ filetype", myfile. postedfile. contenttype );
Cmd. Parameters. addwithvalue ("@ filelength", myfile. postedfile. contentlength. tostring ());
Cmd. Parameters. addwithvalue ("@ filebyte", myfile. filebytes );
Cmd. Parameters. addwithvalue ("@ uploaddate", system. datetime. Now. tostring ("yyyy-mm-dd hh: mm: SS "));
Cmd. Parameters. addwithvalue ("@ downloadcount", 0 );
Cmd. Parameters. addwithvalue ("@ remark", String. Empty );
Try
{
Cmd. Connection. open ();
If (CMD. executenonquery ()> 0)
{
Registerstartupscript ("alert", "<SCRIPT> alert ('upload successful! ') </SCRIPT> ");
}
Else
{
Registerstartupscript ("alert", "<SCRIPT> alert ('upload failed! ') </SCRIPT> ");
}
}
Catch (sqliteexception ex)
{
Console. Write (ex. Message );
}
Finally
{
Cmd. Connection. Close ();
}
}
Else
{
Registerstartupscript ("alert", "<SCRIPT> alert ('The photo format is incorrect. Please reselect it! ') </SCRIPT> ");
}
2. $ Demo:
String SQL = "update files set downloadcount = downloadcount + 1 where id = $ id ";
Sqlitecommand cmd = new sqlitecommand (SQL, new sqliteconnection (datasouce ));
Cmd. Parameters. addwithvalue ("$ id", fileid );
Try
{
Cmd. Connection. open ();
Cmd. executenonquery ();
}
Catch (exception ex)
{
Console. Write (ex. Message );
}
Finally
{
Cmd. Connection. Clone ();
}
I personally think SQLite is quite good, at least better than access. Some of the applications I personally see are the China Mobile Feixin client. Program Google Chrome.
download source code: storeimage.zip