我能够将 Access 中的数据收集到我的 texbox 中,但日期不会停止给出错误。有没有办法抓住日期或者那是不可能的?在这个网站上没有任何地方可以找到将日期转换为字符串以显示到文本框中的souluiton。任何帮助都会很棒,否则我必须将数据库日期更改为字符串。
//Dates not displaying, only errors in the while loop
//strBirthday = dr["STU_BIRTHDAY"].ToString(); This won't diplay like the other 2 strings.
protected void btnQuery_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\\collection\\database.accdb");
string strQueryString = "SELECT STU_NAME, STU_ADDRESS, STU_BIRTHDATE FROM Students WHERE STU_ID = @SID";
OleDbCommand com = new OleDbCommand(strQueryString, con);
com.Parameters.AddWithValue("SID", txtStuID.Text.Trim());
con.Open();
OleDbDataReader dr = com.ExecuteReader();
string strName = "";
string strAddress = "";
string strBirthday = "";
while (dr.Read())
{
strName = dr["STU_NAME"].ToString();
strAddress = dr["STU_ADDRESS"].ToString();
strBirthday = dr["STU_BIRTHDAY"].ToString();
}
txtStuName.Text = strName;
txtStuAddress.Text = strAddress;
txtStuBirthDate.Text = strBirthday;
dr.Close();
con.Close();
}