0

I asked a question [HERE] and we got all the information stored in the database SQL Server CE database.

The question remains now how to get the information stored back into variables.

This line of code:

myReader.SqlCeReader();

will not compile, I am asked if I have missed a compiler reference what ever that is.

The information is stored as strings with an Integer “ID” primary key.

The information will be used to create shortcuts on a disk suitable for launching, images in paint, executable programs and so on. They should not be more than strings which is why I find it hard to do, it should be simple.

A sample record

id=int NstacksName=String NstacksPath=String.

I think I have it all wrong and am surprised it even compiles this far.

private void label2_Click(object sender, EventArgs e)
{
    string DirName;

    SqlCeConnection conn = new SqlCeConnection("Data Source=C:\\Users\\username\\Documents\\Visual Studio 2010\\Projects\\NStacks1\\NStacks1\\Database1.sdf");

    String name;

    try
    {
        conn.Open();

        SqlCeCommand Command = new SqlCeCommand("SELECT * FROM NStacks1 WHERE ID = 1", conn);

        DataTable Data = new DataTable();
        SqlCeDataAdapter adapter = new SqlCeDataAdapter(Command);

        SqlCeDataReader myReader;

        try
        {
             myReader.SqlCeReader();

             DirName = Data.ToString();
             con.Close();
             name = DirName;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         con.Close();
     }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Data
  • 113
  • 2
  • 11
  • Do you understand the difference between a class or type and a variable? You are creating the variable `adapter`, but then you _never_ use it. Then again, you are creating a variable `myReader` without actually assigning it any value, and you try to execute a method of that variable. Then you do something with `Data`, which is an empty `DataTable` - I wonder what you expect to be the result of that... – oerkelens Sep 28 '18 at 18:09
  • Like I said I feel Ive got it all wrong, I pieced it together form several youtube videos so Its bound to be weird. I think I do not know how to do it. – Data Sep 28 '18 at 18:22

1 Answers1

0
    private void button4_Click(object sender, EventArgs e)
    {
        string SName, NStackPath;

        string source=("Data Source=C:\\Users\\username\\Documents\\Visual Studio 2010\\Projects\\NStacks1\\NStacks1\\Database1.sdf");
        SqlCeConnection Con = new SqlCeConnection(source);
        try{
            Con.Open();
            string Query= "SELECT * FROM Nstacks1 WHERE ID=1";
            SqlCeCommand command = new SqlCeCommand(Query , Con);
            SqlCeDataReader dr = command.ExecuteReader();
            if (dr.Read())
            { 
                textBox1.Text=(dr["NStacksName"].ToString());
                label2.Text = (dr["NStacksItem"].ToString());

            }
            Con.Close();
           }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                con.Close();
            }
       }
}
Data
  • 113
  • 2
  • 11