Serign Bah

Serign Bah

  • NA
  • 6
  • 1.6k

Retrieving Data from a database table using DataGridView

May 8 2016 10:49 AM
 Hello Everyone,
 
I have a windows form application where I will enter start-date-time and end-date-time to show result in table, but whenever I run , I have the error below: I am using visual studio 2015 
 
error  
"An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: Conversion failed when converting date and/or time from character string."

This is my code :

Properties.Settings.Default.In_OutConnectionString))
{
c.Open();
// 2
// Create new DataAdapter
string textboxValue1 = textBox1.Text.Trim();
string textboxValue2 = textBox2.Text.Trim();
using (SqlDataAdapter a = new SqlDataAdapter(
"SELECT * FROM People_Tracking WHERE Enter_Exit_Time >='textboxValue1' AND Enter_Exit_Time <='textboxValue2'", c))
{
// 3
// Use DataAdapter to fill DataTable
DataTable t = new DataTable() ;
a.Fill(t);
// 4
// Render data onto the screen
dataGridView1.DataSource = t;
}
}
}
}

Answers (4)