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
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: