我已經設計了一個表格在VS 2008我有包含以下字段的數據庫表中的數據:顯示從SQL數據庫
Fname (char)
MailFrom (char)
MailTo (char)
Subject (char)
Body (char)
MailID (int)
現在我到從數據庫中提取的數據,並在表格上顯示它在各自的領域。
我後面的代碼是:
SqlConnection conn = new SqlConnection(
"Data Source=PTZ1\\SQLEXPRESS;Initial Catalog = test; Integrated Security=SSPI;User ID=sa; [email protected]; Trusted_Connection=True;");
SqlDataReader rdr = null;
try
{
// Open the connection
conn.Open();
// Pass the connection to a command object
SqlCommand cmd = new SqlCommand("select * from testing", conn);
//
// Use the connection
//
// get query results
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Console.WriteLine(rdr[]);
}
}
finally
{
// close the reader
if (rdr != null)
{
rdr.Close();
}
// Close the connection
if (conn != null)
{
conn.Close();
}
}
如何存儲並顯示在控制檯上的數據
我不能用**的**循環在'而(rdr.read())'命令和顯示數據? – Esha
當然你也可以這樣使用它。看到我編輯的答案。 –