Three errors but yet everything looks normal

Lin100

Well-known member
Joined
Dec 12, 2022
Messages
69
Programming Experience
10+
I am trying to simulate a Dlookup function in MS Access where I want to retrieve just one column from
a record in an Access database. There are three errors. I have checked but everything looks normal to me.

Error CS1503 Argument 1: cannot convert from 'string' to 'Prop_Name' Line 25
Error CS0246 The type or namespace name 'Prop_Name' could not be found
(are you missing a using directive or an assembly reference?) Line 34
Error CS1001 Identifier expected Line 34

Lookup a column in an Access Database:
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
         string Apartment_Status;
         DateTime Date_Reserved = DateTime.Today;
         MessageBox.Show("Date_Reserved =  " + Date_Reserved);

         object value = this.dataGridView2.CurrentRow.Cells[7].Value.ToString();
         if (value is DBNull) { return; }
         Apartment_Status = value.ToString();
         MessageBox.Show("Apartment_Status =  " + Apartment_Status);

         switch (Apartment_Status)
           {
              case "Reserved":
                  Reservation2 R2 = new Reservation2();
                  R2.Show();
              break;

              case "Vacant":
                  Reservation1 R1 = new Reservation1();
                  R1.Property_Name.Text = this.dataGridView2.CurrentRow.Cells[0].Value.ToString();
                  R1.Unit_Number.Text = this.dataGridView2.CurrentRow.Cells[1].Value.ToString();

                  string Prop_Name = R1.Property_Name.Text;
                  Obtain_Property_ID(Prop_Name);        Error  CS1503.  
                  R1.Show();
                break;

                default:
                break;
             }


 void Obtain_Property_ID(Prop_Name)        Error  CS0246,  Error  CS1001.
     {
          OleDbConnection con = new OleDbConnection();
          con.ConnectionString = ConfigurationManager.ConnectionStrings["Apartment_Management.Properties.Settings.AMS_2007ConnectionString"].ToString();
          con.Open();
          MessageBox.Show("Obtain_Property_ID procedure");
          OleDbCommand cmd = new OleDbCommand();
           
          String Prop_Name = "Modern Plano";
          cmd.CommandText = "SELECT Property_ID FROM Property WHERE Property_Name = '" + Prop_Name + "' ";

          cmd.Connection = con;
          OleDbDataAdapter da = new OleDbDataAdapter(cmd);
          DataSet ds = new DataSet();
          da.Fill(ds);
         
          var Property_ID = ds.Tables[0];
          MessageBox.Show("Property_ID " + Property_ID);
      }
 }
 
Last edited:
1) First, are you wedded to keeping the access database?
Yes.

2) I would love to work in C# to connect to a Sequel Server 2000.
I have the software but the Windows XP computer is down
so I cannot load Sequel Server into it. In doing so I can
connect C# to tables in Sequel Server.
Is there some kind of light or small version of Sequel Server
I could download where I could create a Sequel Server tables
so that C# could connect to it ?
This small version of Sequel Server would only allowed a user
to create tables, view, and constraint and nothing more.
 
2) I would love to work in C# to connect to a Sequel Server 2000.
I have the software but the Windows XP computer is down
so I cannot load Sequel Server into it. In doing so I can
connect C# to tables in Sequel Server.
Is there some kind of light or small version of Sequel Server
I could download where I could create a Sequel Server tables
so that C# could connect to it ?
This small version of Sequel Server would only allowed a user
to create tables, view, and constraint and nothing more.
 
Note that LocalDB is only really intended for development and testing purposes. If that's all you're doing then you're good to go. LocalDB has been a standard component in VS for some time. If you are looking to deploy an app developed using LocalDB then you ought to have at least SQL Server Express available in the environment you're deploying to. If you want to stick with a file-based database but avoid Access, SQLite is the recommended option.
 
Back
Top Bottom