Since you're using a relative directory in your connection string (a filename with no path), make sure your Environment.CurrentDirectory is pointing to the right place at all times.
For example, if you use an OpenFileDialog or SaveFileDialog, those classes change the CurrentDirectory. Once your current directory changes, your code will no longer be able to open the database. I highly recommend using this datasource: Data Source=|DataDirectory|database.db That way |DataDirectory| will be expanded at runtime to an absolute path. -----Original Message----- From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Alessio Forconi Sent: Sunday, January 11, 2009 10:19 AM To: General Discussion of SQLite Database Subject: SPAM: Re: [sqlite] How to create a Datatable [first steps of newbie] It means that the connection that I use in the code that I showed you is the same as that used in other parts of the program, only that we do not work, I get that bug that I told you. Thanks for your availability. Roosevelt Anderson ha scritto: > What does your connection string look like? > > On Fri, Jan 9, 2009 at 2:36 PM, Alessio Forconi <forco...@gmail.com> wrote: > >> Thanks for your suggestion, I do not think that is the problem because >> the connection is the one used with success in other parts of the >> program, you show the code that I wrote following your suggestions: >> >> string sqlString = "SELECT * FROM Proclamatori"; >> conn = new SQLiteConnection(connString); >> try >> { >> conn.Open(); >> SQLiteDataAdapter apt = new SQLiteDataAdapter(sqlString, conn); >> DataTable dtProclamatori = new DataTable(); >> apt.Fill(dtProclamatori); >> } >> catch (SQLiteException ex) >> { >> MessageBox.Show(ex.Message); >> } >> finally >> { >> conn.Close(); >> } >> >> >> I know that there are groups for microsoft c # but that does not seem >> like a software applications that are not microsoft: ( >> >> Roosevelt Anderson ha scritto: >> >>> It should be "Data Source=database.db" not "DataSource=database.db". I >>> didn't realize this because of the line break in the email. This will >>> create a new, empty database named database.db in the directory where >>> your application is running. >>> >>> On Fri, Jan 9, 2009 at 7:32 AM, Alessio Forconi <forco...@gmail.com> wrote: >>> >>> >>>> Thanks... >>>> >>>> I get this error >>>> >>>> "Data Source cannot be empty. Use :memory: to open an in-memory database" >>>> >>>> but the connection is sattamante the same as that used in other parts of >>>> the program >>>> >>>> Roosevelt Anderson ha scritto: >>>> >>>> >>>>> If you trying to extract data from a sqlite database to a DataTable >>>>> here is how you do it using the .Net data provider: >>>>> >>>>> SQLiteConnection conn = new SQLiteConnection("Data >>>>> Source=database.db"); >>>>> conn.Open(); >>>>> SQLiteDataAdapter apt = new SQLiteDataAdapter("select * from tbl", conn); >>>>> DataTable dt = new DataTable(); >>>>> apt.Fill(dt); >>>>> conn.Close(); >>>>> >>>>> >>>>> >>>>> >>>>> On Thu, Jan 8, 2009 at 11:28 AM, Alessio Forconi <forco...@gmail.com> wrote: >>>>> >>>>> >>>>> >>>>>> Hello everyone, >>>>>> >>>>>> I am making the first steps with the programming and I want to help >>>>>> create a DataTable from a database sqlite with C #. >>>>>> >>>>>> Can you give me an example of how do I create it without using a >>>>>> dataset? >>>>>> >>>>>> Thank you very much for your help. >>>>>> _______________________________________________ >>>>>> sqlite-users mailing list >>>>>> sqlite-users@sqlite.org >>>>>> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users >>>>>> >>>>>> >>>>>> >>>>>> >>>>> _______________________________________________ >>>>> sqlite-users mailing list >>>>> sqlite-users@sqlite.org >>>>> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users >>>>> >>>>> >>>>> >>>>> >>>> _______________________________________________ >>>> sqlite-users mailing list >>>> sqlite-users@sqlite.org >>>> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users >>>> >>>> >>>> >>> _______________________________________________ >>> sqlite-users mailing list >>> sqlite-users@sqlite.org >>> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users >>> >>> >>> >> _______________________________________________ >> sqlite-users mailing list >> sqlite-users@sqlite.org >> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users >> >> > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users