Serign Bah

Serign Bah

  • NA
  • 6
  • 1.6k

Using VC++ MFC diaglog to retrieve data from database:

May 9 2016 1:48 PM
Hello Everyone,
 
I used the following code in C# using Windows Form Application to retrieve data from a database, and i works well, but I could I use similar code to do the same in VC++ MFC dialog? 

Code in C# Windows Form Application: 
 
using (SqlConnection c = new SqlConnection(Properties.Settings.Default.In_OutConnectionString))
{
c.Open();
DateTime startDateTime = Convert.ToDateTime(textBox1.Text);
DateTime endDateTime = Convert.ToDateTime(textBox2.Text);
string query = "SELECT * FROM People_Tracking WHERE Enter_Exit_Time BETWEEN @startDateTime AND @endDateTime ;";
SqlCommand cmd = new SqlCommand(query, c);
cmd.Parameters.Add("@startDateTime", SqlDbType.DateTime).Value = startDateTime;
cmd.Parameters.Add("@endDateTime", SqlDbType.DateTime).Value = endDateTime;
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable t = new DataTable();
adapter.Fill(t);
dataGridView1.DataSource = t;
}
}
MFC dialog screen shot :
 
My database screen shot: