The same code works here, tried on 3 different devices; the only difference
I can see offhand is the connection.CreateCommand instead of new
Sqlitecommand(). You don't even have any errors on logcat?

On 18 May 2012 14:02, mdurli <mdu...@gmail.com> wrote:

> Tried on a Motorola ET1 Tablet and on a Motorola Droid, both with Android
> 2.3.
>
> I tried other samples, and this code for example works:
>
> string dbPath = 
> Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),"items.db3");
>             bool exists = File.Exists(dbPath);
>             if (!exists) SqliteConnection.CreateFile(dbPath);
>             var connection = new SqliteConnection("Data Source=" + dbPath);
>             connection.Open();
>             if (!exists)
>             {
>                 // This is the first time the app has run and/or that we need 
> the DB.
>                 // Copy a "template" DB from your assets, or programmatically 
> create one.
>                 var commands = new[]{
>         "CREATE TABLE [Items] (Key ntext, Value ntext);",
>         "INSERT INTO [Items] ([Key], [Value]) VALUES ('sample', 'text')",
>         "INSERT INTO [Items] ([Key], [Value]) VALUES ('sample2', 'text2')"
>     };
>                 foreach (var command in commands)
>                 {
>                     using (var c = connection.CreateCommand())
>                     {
>                         c.CommandText = command;
>                         c.ExecuteNonQuery();
>                     }
>                 }
>             }
>             // use `connection`...
>             // here, we'll just append the contents to a TextView
>             using (var contents = connection.CreateCommand())
>             {
>                 contents.CommandText = "SELECT [Key], [Value] from [Items]";
>                 var r = contents.ExecuteReader();
>                 while (r.Read())
>                     textView1.Text += string.Format("\n\tKey={0}; Value={1}",
>                             r["Key"].ToString(), r["Value"].ToString());
>                 r.NextResult();
>             }
>             connection.Close();
>
>
> I can start from here now, but I'm still wondering what't wrong in the other 
> code (and why it didn't trap the error but just exit the procedure when 
> .Read()
>
> Thanks,
> Mattia
>
>
>
>
>
>
> Il 18/05/2012 14:30, ledz [via Mono for Android] ha scritto:
>
> On what real device did you test?
>
> On 18 May 2012 12:57, mdurli <[hidden 
> email]<http://user/SendEmail.jtp?type=node&node=5709909&i=0>
> > wrote:
>
>> Hello,
>>
>> I tried both with emulator and with real device.
>>
>> Thanks,
>> Mattia
>>
>>
>> Il 18/05/2012 13:23, Wally McClure [via Mono for Android] ha scritto:
>>
>>  Mattia,
>>
>>  I haven't tried this under 4.2, but when the book was written, the data
>> readers did not work in the emulator under the 4.0x versions we tested with
>> at the time, but worked in every physical device that we tested against.
>>  The joys of the emulator.
>>
>>  Wally
>>
>>  ------------------------------
>> Date: Fri, 18 May 2012 13:12:04 +0200
>>  From: [hidden email]<http://user/SendEmail.jtp?type=node&node=5709904&i=0>
>> To: [hidden email] <http://user/SendEmail.jtp?type=node&node=5709904&i=1>
>>  CC: [hidden email]<http://user/SendEmail.jtp?type=node&node=5709904&i=2>
>>
>> Subject: Re: [mono-android] SQLite error
>>
>> Hello Wally,
>>
>> thanks for the quick response.
>>
>>
>>    - On that specific example, there should be another button on that
>>    form.  IIRC, the other button should insert some data into the table.  
>> When
>>    I get down to my office, I'll verify this.
>>
>>   Yes there is a button and it completes the DB creation and sample data
>> insertion with success, so that part works.
>> The problem is with the second button that should fetch the data with a
>> datareader.
>>
>> What I don't understand is why I can follow the debug until the "while
>> (sdr.Read())" line, and then clicking F10 the debug jumps at the end of the
>> file... without rising any error, even if it's in the try/catch block.
>> I tried both in emulator and in real device.
>>
>> Debug should work, because there is a third button that connects to a
>> SQLServer DB, that fails correctly during the connection in its try/catch
>> block.
>>
>> Thanks,
>> Mattia
>>
>>
>>    - You should be able to create a DB and store it in the assets
>>    directory.  When the application is first deployed and run, you can copy
>>    the db file out.  I haven't done this, but you "should" be able to do 
>> this.
>>     I'm a db guy at heart, so sql commands are easy to put together for me,
>>    plus I like to use them when I update apps.
>>    - Accessing the db remotely is way more complicated than we are used
>>    to with VS.  You can use adb to connect to the db, but you have to have 
>> the
>>    device.  I'm sure that there are higher level tools that you can use, but 
>> I
>>    am not aware of them.
>>
>>
>>  Wally
>>
>>  > Date: Fri, 18 May 2012 03:35:23 -0700
>>  > From: [hidden email]<http://user/SendEmail.jtp?type=node&node=5709904&i=3>
>> > To: [hidden email]<http://user/SendEmail.jtp?type=node&node=5709904&i=4>
>>   > Subject: [mono-android] SQLite error
>> >
>> > Hello,
>> >
>> > I'm having this problem with the sample code of the wrox book "Pro
>> Android
>> > programming with Mono for Android", InternalNetworkData sample.
>> > First it creates a DB and fills it with data, with success, then tries
>> to
>> > read the data with a SqliteDataReader.
>> > I tried to debug it and when it gets to the line "while (sdr.Read())"
>> the
>> > debug line jumps to the end of the file, no errors, and non processing,
>> > application stil running, and I can press the button to get the data
>> again.
>> > What's wrong? with the code and with my debug that can't get the error.
>> >
>> > string DatabaseName = "UserData.db3";
>> > string documents = System.Environment.GetFolderPath(
>> > System.Environment.SpecialFolder.Personal);
>> > string db = Path.Combine(documents, DatabaseName);
>> > var conn = new SqliteConnection("Data Source=" + db);
>> > var strSql = "select Name from Customer where STATEID=@STATEID";
>> > var cmd = new SqliteCommand(strSql, conn);
>> > cmd.CommandType = CommandType.Text;
>> > cmd.Parameters.Add(new SqliteParameter("@STATEID", 2));
>> >
>> > tv.Text = "";
>> >
>> > try
>> > {
>> > conn.Open();
>> > SqliteDataReader sdr = cmd.ExecuteReader();
>> > while (sdr.Read())
>> > {
>> > tv.Text = Convert.ToString(sdr["Name"]);
>> > }
>> > }
>> > catch (System.Exception sysExc)
>> > {
>> > tv.Text = sysExc.Message;
>> > }
>> > finally
>> > {
>> > if (conn.State != ConnectionState.Closed)
>> > {
>> > conn.Close();
>> > }
>> > conn.Dispose();
>> >
>> > }
>> >
>> >
>> > By the way, is there a way with a thirdy part software or even with vs
>> to
>> > create a sqlite DB and deploy it with the application? and maybe even to
>> > access the sqlite DBs in the connected device? asking too much?
>> >
>> > Thanks!
>> > Mattia
>> >
>> > --
>> > View this message in context:
>> http://mono-for-android.1047100.n5.nabble.com/SQLite-error-tp5709898.html
>> > Sent from the Mono for Android mailing list archive at Nabble.com.
>> > _______________________________________________
>> > Monodroid mailing list
>>   > [hidden email] <http://user/SendEmail.jtp?type=node&node=5709904&i=5>
>> >
>> > UNSUBSCRIBE INFORMATION:
>> > http://lists.ximian.com/mailman/listinfo/monodroid
>>
>>
>> _______________________________________________
>> Monodroid mailing list
>> [hidden email] <http://user/SendEmail.jtp?type=node&node=5709904&i=6>
>>
>> UNSUBSCRIBE INFORMATION:
>> http://lists.ximian.com/mailman/listinfo/monodroid
>>
>>
>>  ------------------------------
>>  If you reply to this email, your message will be added to the
>> discussion below:
>>
>> http://mono-for-android.1047100.n5.nabble.com/SQLite-error-tp5709898p5709904.html
>>  To unsubscribe from SQLite error, click here.
>> NAML<http://mono-for-android.1047100.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>>
>> ------------------------------
>> View this message in context: Re: SQLite 
>> error<http://mono-for-android.1047100.n5.nabble.com/SQLite-error-tp5709898p5709908.html>
>>
>> Sent from the Mono for Android mailing list 
>> archive<http://mono-for-android.1047100.n5.nabble.com/>at Nabble.com.
>>
>> _______________________________________________
>> Monodroid mailing list
>> [hidden email] <http://user/SendEmail.jtp?type=node&node=5709909&i=1>
>>
>> UNSUBSCRIBE INFORMATION:
>> http://lists.ximian.com/mailman/listinfo/monodroid
>>
>>
>
>
>  --
> Gonçalo Oliveira
>
>
> _______________________________________________
> Monodroid mailing list
> [hidden email] <http://user/SendEmail.jtp?type=node&node=5709909&i=2>
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://mono-for-android.1047100.n5.nabble.com/SQLite-error-tp5709898p5709909.html
>  To unsubscribe from SQLite error, click here.
> NAML<http://mono-for-android.1047100.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
>
> ------------------------------
> View this message in context: Re: SQLite 
> error<http://mono-for-android.1047100.n5.nabble.com/SQLite-error-tp5709898p5709911.html>
> Sent from the Mono for Android mailing list 
> archive<http://mono-for-android.1047100.n5.nabble.com/>at Nabble.com.
>
> _______________________________________________
> Monodroid mailing list
> Monodroid@lists.ximian.com
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
>
>


-- 
Gonçalo Oliveira
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to