mysql 2008 데이터베이스에서 필드를 가져 오려고합니다. 나는 (내가 전에 몇 번 사용했던)이 작은 코드를 작성 - 그것은 나에게이 서버 오류를주고 유지 :컬럼이 존재하지 않습니다 서버 오류 -하지만 SQL 서버 관리가 말합니다
Column 'Previous Login' does not belong to table Table.
Line 47: DateTime userEntry = Convert.ToDateTime(ds1.Tables[0].Rows[0]["Previous Login"]);
그러나 그것은 존재! 내가 같은 쿼리를 사용하여 insql 서버 관리를 잘 작동하므로 반환 데이터가 좋을 것 같아요.
감사합니다.
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=(local);database=PhilipsMaterials;Integrated Security=SSPI;";
con.Open();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
// SQL Query that returns only the messages from the last 2 weeks starting with the most recent one.
string sql = "Select * From Messages Where DATEDIFF(DAY,Date,GETDATE()) <= 14 ORDER BY Date Desc";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
da.Fill(ds);
dt = ds.Tables[0];
showMsgs.DataSource = ds;
showMsgs.DataBind();
// new message notification
string username = Convert.ToString(Session["username"]);
username = username.Substring(username.IndexOf("\\") + 1);
DataSet ds1 = new DataSet();
DataTable dt1 = new DataTable();
string sqluser = "Select * From [PhilipsMaterials].[dbo].[Employees] Where username='" + username + "'";
SqlDataAdapter da1 = new SqlDataAdapter(sqluser, con);
da.Fill(ds1);
dt1 = ds1.Tables[0];
DateTime userEntry = Convert.ToDateTime(ds1.Tables[0].Rows[0]["Previous Login"]);
DateTime lastMsg = new DateTime();
lastMsg = Convert.ToDateTime(ds.Tables[0].Rows[0]["Date"]);
int compared = DateTime.Compare(userEntry, lastMsg);
if (compared < 0) { notification.Visible = true; }
con.Close();
}
제 생각에 공간이 제거되었거나 다른 문자로 변환되었습니다. 디버거에서'ds1.Tables [0] .Columns'을보고 이름이 무엇인지 확인하십시오. –
제 경험으로 항상 열 이름의 공백을 좋아하지 않았습니다. – Taryn
'WHERE username = ' "+ username +"' "'절대하지 마세요! SqlParamter's for this this. http://en.wikipedia.org/wiki/SQL_injection –