Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Iam write program that use Access DataBase , but my problem : - when I Click Find
Button you just find a Last record was add in a DataBase .

Please How can I solve this problem ...
Posted

1 solution

give the code block to identify the problem / explain more ...
 
Share this answer
 
Comments
mahmal10 22-Jan-12 5:52am    
private int _patientId = 0;
private string _Firstname = "";
private string _Lastname = "";
private int _defualtNO = 0;

public int DegualtnO
{
get { return _defualtNO; }
set { _defualtNO = value; }
}

public int PatientId
{
get { return _patientId; }
set { _patientId = value; }
}

public string Firstname
{
get { return _Firstname; }
set { _Firstname = value; }
}

public string Lastname
{
get { return _Lastname; }
set { _Lastname = value; }
}

public void GetPatient(int pID)
{
string connect_string = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Anwar\MyData1.accdb";
OleDbConnection cn = new OleDbConnection(connect_string);
cn.Open();
string ss = "select*from[Patient]";
OleDbCommand cd = new OleDbCommand(ss, cn);
OleDbDataReader dr = cd.ExecuteReader();


// con.Open();

cmdSelect.Parameters["@PatientID"].Value = pID;

// OleDbDataReader dr;
// dr = cmdSelect.ExecuteReader();



while (dr.Read())
{
// _patientId = (dr.IsDBNull(dr.GetOrdinal("PatientId")))? 9999 :int.Parse(dr["PatientId"].ToString());
_patientId = (int)dr["PatientId"];
_Firstname = (string)dr["Firstname"];
_Lastname = (string)dr["Lastname"];

}

dr.Close();
cn.Close();
//con.Close();

/*}
catch (OleDbException err)
{

}*/
}
mahmal10 22-Jan-12 5:55am    
and I Called the GetPatient(int ..) By Find Button , the Code Of Button Find is : -

private Patients _patient = new Patients();
private void btnFind_Click(object sender, EventArgs e)
{
try
{
_patient = new Patients();

_patient.GetPatient(int.Parse(txtPatientID.Text));

txtPatientID.Text = _patient.PatientId.ToString();
txtFirstName.Text = _patient.Firstname;
txtLastName.Text = _patient.Lastname;

btnDelete.Enabled = true;
btnSave.Enabled = false;
}
catch (FormatException ez)
{
MessageBox.Show("Plz Enter Right Format", ez.ToString());

}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900