Click here to Skip to main content
15,907,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i try to differentiate the user and it's task.
i make windows app in c# about physiotherapy management system.
i want to fetch records from db . there are 2 tables patient_mstr for new user and old_patient for existing user.

i want to do that if user is visited 2nd time then records will be shown from patient_mstr and if visted more than 2nd time then reocrds will be shown from old_patient.

i did another logic which i realize, thank u in advance.

What I have tried:

private void txtsno_KeyDown(object sender, KeyEventArgs e)
{
cn.Open();
try
{

if (e.KeyCode == Keys.Enter)
{
// this query for retrieve just serial number.
OleDbCommand cmdt = new OleDbCommand("select top 1 * from patient_mstr where Contact_no=@Contact_no", cn);
cmdt.Parameters.Add(new OleDbParameter("@Contact_no", txtsno.Text));
// store value in userexist variable.
int UserExist = (int)cmdt.ExecuteScalar();
// this query for visiting numbers.
OleDbCommand vst = new OleDbCommand("select count(*) from patient_mstr where Contact_no=@Contact_no",cn);
vst.Parameters.Add(new OleDbParameter("@Contact_no",txtsno.Text));

// store value in rec variable.
int rec = (int)vst.ExecuteScalar();
//OleDbDataReader dr2 = cmdt.ExecuteReader();
if (UserExist == 1)
{

//if (e.KeyCode == Keys.Enter)
//{
OleDbCommand cmd = new OleDbCommand("select P_name,E_date,Main_pain,Sub_pain,V_charge,Paid,Description from patient_mstr where Contact_no=@Contact_no", cn);
cmd.Parameters.Add(new OleDbParameter("@Contact_no", txtsno.Text));
// cn.Open();
cmd.ExecuteNonQuery();
OleDbDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
lblapnm.Text = (string)dr["P_name"];
lblapain.Text = (string)dr["Main_pain"] + " , " + (string)dr["Sub_pain"];
lbld.Text = (string)dr["Description"];
//lblcrgh.Text = dr["V_charge"].ToString();
//lblpdinf.Text = dr["Paid"].ToString();
lbladt.Text = dr["E_date"].ToString();
//pb_old.Image = (Image)dr["Image"];

}
dr.Close();
}
else if (UserExist > 1)
{
OleDbCommand cmd = new OleDbCommand("select P_name,E_date,Pain,Description,Image_new from old_patient where Contact_no=@Contact_no", cn);
cmd.Parameters.Add(new OleDbParameter("@Contact_no", txtsno.Text));
// cn.Open();
cmd.ExecuteNonQuery();
OleDbDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
lblapnm.Text = (string)dr["P_name"];
lblapain.Text = (string)dr["Main_pain"] + " , " + (string)dr["Sub_pain"];
lbld.Text = (string)dr["Description"];
//lblcrgh.Text = dr["Total_charge"].ToString();
//lblpdinf.Text = dr["Total_paid"].ToString();
lbladt.Text = dr["E_date"].ToString();
//pb_old.Image = (Image)dr["Image_new"];

}
dr.Close();
lbldtr.Text = rec.ToString();
}
}

//cn.Close();
}


catch (Exception c)
{
MessageBox.Show(c.Message);
}
cn.Close();
}
Posted
Updated 17-Sep-16 2:58am
Comments
OriginalGriff 17-Sep-16 7:36am    
And?
What is your problem?
What does that do that you didn't expect, or not do that you did?
Member 11572517 17-Sep-16 8:20am    
sorry sir,i did above logic that didn't work proper.
Patrice T 17-Sep-16 9:33am    
"didn't work proper" is not informative.
Member 11572517 17-Sep-16 9:38am    
ok, sir, i m very poor in this things.
Patrice T 17-Sep-16 9:41am    

1 solution

i solved it sir, my whole logic is perfect but, i m just less mistake of understand that create this problem, i did

oledbcommand cmdt = new oledbcommand("select count(*) from old_patient where Contact_no=@Contact_no",cn);


just table name and total no. of records. this is my mistake.

and regarding this
i changed in of condition too.

if(UserExist == 0) that means this is 2nd time patient record is enter so, that i fetch record from patient_mstr table.
else if(UserExist != 0) that means there is record then i fetch record from old_mstr table.

and it's work.
 
Share this answer
 
Comments
Karthik_Mahalingam 18-Sep-16 2:08am    
good that you have posted the solution and closed this post.

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