Click here to Skip to main content
14,660,523 members
Home » Discussions » Database
   

Database

 
GeneralRe: Read data from Azure database with C#-application, without installing a lot of applications? Pin
Richard MacCutchan27-Apr-20 2:46
mveRichard MacCutchan27-Apr-20 2:46 
GeneralRe: Read data from Azure database with C#-application, without installing a lot of applications? Pin
Mycroft Holmes27-Apr-20 12:35
professionalMycroft Holmes27-Apr-20 12:35 
GeneralRe: Read data from Azure database with C#-application, without installing a lot of applications? Pin
arnold_w27-Apr-20 19:44
Memberarnold_w27-Apr-20 19:44 
GeneralRe: Read data from Azure database with C#-application, without installing a lot of applications? Pin
Mycroft Holmes27-Apr-20 21:43
professionalMycroft Holmes27-Apr-20 21:43 
AnswerRe: Read data from Azure database with C#-application, without installing a lot of applications? Pin
Richard MacCutchan25-Apr-20 21:42
mveRichard MacCutchan25-Apr-20 21:42 
AnswerRe: Read data from Azure database with C#-application, without installing a lot of applications? Pin
jschell26-Apr-20 10:18
Memberjschell26-Apr-20 10:18 
AnswerRe: Read data from Azure database with C#-application, without installing a lot of applications? Pin
arnold_w30-Apr-20 4:16
Memberarnold_w30-Apr-20 4:16 
QuestionNo rows returned using SQLiteParameters, but rows returned with direct query Pin
Uranium-23518-Apr-20 21:59
MemberUranium-23518-Apr-20 21:59 
Ok, here is the code in my class

static public DataTable query_search(string sqlite_query, SQLiteParameter[] parameters)
 {
     SQLiteConnection sqlite_conn = new SQLiteConnection("Data Source=test.db;Version=3;Compress=True;Synchronous=Full;");

     sqlite_conn.Open();
     SQLiteCommand sqlite_cmd;
     sqlite_cmd = sqlite_conn.CreateCommand();
     sqlite_cmd.CommandText = sqlite_query;
     SQLiteDataReader sqlite_datareader;

     sqlite_cmd.Parameters.AddRange(parameters);
     sqlite_datareader = sqlite_cmd.ExecuteReader();

     DataTable returnTable = new DataTable();
     returnTable.Load(sqlite_datareader);

     writedebug(returnTable.Rows.Count.ToString());

     sqlite_conn.Close();
     sqlite_datareader.Close();
     return returnTable;
 }


writedebug writes 0 rows

My call

private void button1_Click(object sender, EventArgs e)
{
    if (search.Text.Trim() != "")
    {

        SQLiteParameter[] param = {
            new SQLiteParameter("%@search%", "paul") //used direct string for debug //search.Text)
        };

        customerList.Rows.Clear();

        DataTable searchinfo = database.query_search("SELECT id, firstname, lastname FROM customers WHERE firstname LIKE '@search' OR lastname LIKE '@search'", param);

        MessageBox.Show(searchinfo.Rows.Count.ToString());

        foreach (DataRow row in searchinfo.Rows)
        {
            customerList.Rows.Add(row[0].ToString(), row[1].ToString() + " " + row[2].ToString());
        }
    }
}

if I replace @search in the query with "%paul%" (in the database) writedebug turns 2 and it adds the rows to the form table

I can query and put the search.Text directly into the string like SELECT id, firstname, lastname FROM customers WHERE firstname LIKE '" + search.Text + "' OR lastname LIKE '" + search.Text + '" but I needed sanitized queries (even though im the only one using this software), adding a % will make it return all rows

I've used SQLiteParameter for INSERT INTO with another function successfully. please help

thanks
AnswerRe: No rows returned using SQLiteParameters, but rows returned with direct query Pin
Richard MacCutchan18-Apr-20 22:50
mveRichard MacCutchan18-Apr-20 22:50 
GeneralRe: No rows returned using SQLiteParameters, but rows returned with direct query Pin
Uranium-23519-Apr-20 3:33
MemberUranium-23519-Apr-20 3:33 
GeneralRe: No rows returned using SQLiteParameters, but rows returned with direct query Pin
Richard MacCutchan19-Apr-20 4:11
mveRichard MacCutchan19-Apr-20 4:11 
GeneralRe: No rows returned using SQLiteParameters, but rows returned with direct query Pin
Uranium-23519-Apr-20 4:39
MemberUranium-23519-Apr-20 4:39 
GeneralRe: No rows returned using SQLiteParameters, but rows returned with direct query Pin
Richard MacCutchan19-Apr-20 4:52
mveRichard MacCutchan19-Apr-20 4:52 
GeneralRe: No rows returned using SQLiteParameters, but rows returned with direct query Pin
Uranium-23519-Apr-20 16:37
MemberUranium-23519-Apr-20 16:37 
GeneralRe: No rows returned using SQLiteParameters, but rows returned with direct query Pin
Richard MacCutchan19-Apr-20 21:46
mveRichard MacCutchan19-Apr-20 21:46 
GeneralRe: No rows returned using SQLiteParameters, but rows returned with direct query Pin
Uranium-23519-Apr-20 23:05
MemberUranium-23519-Apr-20 23:05 
GeneralRe: No rows returned using SQLiteParameters, but rows returned with direct query Pin
Richard MacCutchan19-Apr-20 23:35
mveRichard MacCutchan19-Apr-20 23:35 
GeneralRe: No rows returned using SQLiteParameters, but rows returned with direct query Pin
Uranium-23520-Apr-20 9:44
MemberUranium-23520-Apr-20 9:44 
GeneralRe: No rows returned using SQLiteParameters, but rows returned with direct query Pin
Richard MacCutchan20-Apr-20 21:36
mveRichard MacCutchan20-Apr-20 21:36 
GeneralRe: No rows returned using SQLiteParameters, but rows returned with direct query Pin
Richard Deeming21-Apr-20 0:35
mveRichard Deeming21-Apr-20 0:35 
Questioncomplicated SQL Join request from two server Pin
Member 1473386615-Apr-20 21:11
MemberMember 1473386615-Apr-20 21:11 
AnswerRe: complicated SQL Join request from two server Pin
Richard Deeming16-Apr-20 0:08
mveRichard Deeming16-Apr-20 0:08 
GeneralRe: complicated SQL Join request from two server Pin
Member 1473386616-Apr-20 2:36
MemberMember 1473386616-Apr-20 2:36 
GeneralRe: complicated SQL Join request from two server Pin
Richard Deeming16-Apr-20 2:48
mveRichard Deeming16-Apr-20 2:48 
GeneralRe: complicated SQL Join request from two server Pin
Member 1473386616-Apr-20 3:04
MemberMember 1473386616-Apr-20 3:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.