none
can't create table no PK sqlite RRS feed

  • Question

  • Hi

    With this code

    async public Task SaveItem()
            {
    
                //this.list1.Visibility = Visibility.Visible;
    
                var path = ApplicationData.Current.LocalFolder.Path + @"\objetostempos.db";
                //var path = "C:\Users\Rui\Desktop\Apps e net\UniversalApps\App1\App1\App1.Shared\plantasmedicinais5.sqlite";
    
                var db = new SQLiteAsyncConnection(path);
    
                List<string> listOfAppointmentDetails = new List<string>();
                string appointmentDetails = null;
                //string appointmentDetails2 = null;
                var queryAppointments = await db.QueryAsync<App.Appointments>("select * from tempos");//aqui vai ler a tabela na BD
                //var queryAppointments = await db.QueryAsync<tempos2>("select * from tempos");//aqui vai ler a tabela na BD
                Debug.WriteLine(queryAppointments);
    
                await db.CreateTableAsync<tempos>();
                await db.CreateTableAsync<tempos2>();
                await db.CreateTableAsync<App.Appointments>();
    
                //CreateTablesResult x = await CreateTableAsync();
    
                foreach (var appointmentItem in queryAppointments)
                {
                    //if (box1.Text == appointmentItem.Designacao)
                    //exemplo: if (str.Contains("TOP") == true)
                    ////if //(
                    ////    (appointmentItem.Designacao.Contains(box1.Text) == true)
                    //& (appointmentItem.Designacao.Contains(box2.Text) == true))
                    ////{
                    //var queryAppointments3 = await db.QueryAsync<App.Appointments>("insert into tempos (nome) values " + timeLeft + "\n");//aqui vai ler a tabela na BD
                    //Debug.WriteLine(queryAppointments3);
    
                    //var queryAppointments2 = await db.QueryAsync<tempos>("INSERT INTO tempos ('nome',objeto1n1) VALUES (no,1);");//aqui vai ler a tabela na BD
                    var queryAppointments2 = await db.QueryAsync<App.Appointments>("select nome from tempos");//aqui vai ler a tabela na BD
                    Debug.WriteLine(queryAppointments2);
                    Debug.WriteLine("antes queryAppointments2");
                    appointmentItem.Designacao = "aba";
    
    
                    await db.UpdateAllAsync(appointmentItem.Designacao);
    
                        appointmentDetails = "\n" + "" + appointmentItem.Designacao + "\n" + appointmentItem.Especie + "\n";
                        listOfAppointmentDetails.Add(appointmentDetails);
                        Debug.WriteLine(appointmentDetails);
                        
                        //Bitmap bmpReturn = null;
    
                        //byte[] byteBuffer = Convert.FromBase64String(base64String);
                        //MemoryStream memoryStream = new MemoryStream(byteBuffer);
    
                        //memoryStream.Position = 0;
    
                        //ok
                        //String stringPath = "ms-appx:///Assets/fotos/" + appointmentItem.foto1;
    
                        //BitmapImage bitmapImage = new BitmapImage();
    
                        //Uri uri = new Uri(stringPath);
                        //bitmapImage.UriSource = uri;
                        //image1.Source = bitmapImage;
    
                        //listOfAppointmentDetails.Add(stringPath);
                        //ok
    
    
                    ////}
                }
    
                ////list1.ItemsSource = listOfAppointmentDetails;
    
            }

    The update makes me get: it has no PK

    How can I change this?

    • Moved by Fei Hu Thursday, January 18, 2018 6:17 AM Thirdparty libs related
    Wednesday, January 17, 2018 10:19 PM

All replies

  • This code does not create the database and create the tables for you. Does that file path have the database? Use a sqlite database program to open it up and see if the structure is there or not.

    Dim Blondedude092 as SkypeUser

    Wednesday, January 17, 2018 10:40 PM
  • Thanks.

    I use: DB Browser for SQLite and see there no changes....

    The DB goes always to an AppData folder that is read only...

    nevertheless I have the database inside the folder of other .cs files....

    Why the database moves to another place?

    Wednesday, January 17, 2018 11:07 PM
  • You can ask about where the database is save here

    https://github.com/sqlitebrowser/sqlitebrowser/issues


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, January 18, 2018 1:05 AM
  • Hello Rui,

    Your issue is more related to third party product, I am afraid it is out of support of C# general question forum which mainly discusses C# programming language, IDE, libraries, samples and tools.

    I suggest that you can consult your issue directly on SQLlite forum: https://github.com/sqlitebrowser/sqlitebrowser/issues for better solution and support.

    If I have misunderstood anything, please feel free to let me know.

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Edited by Fei Hu Thursday, January 18, 2018 6:16 AM
    Thursday, January 18, 2018 6:16 AM
  • Can you confirm that the database exists? 
    if it does exist can you open it with another external database management program to see if it does in fact have the structure that is being used in the code?



    Dim Blondedude092 as SkypeUser

    Saturday, January 27, 2018 9:07 AM