0
我是c#程序員。目前,我嘗試在datagrid-viewer中的sql數據中添加5列中的3列(fileId,filePath,authorName,fileContent,DateSend) fileId和fileContent列是隱藏的。非常感謝你!datagridview顯示從sql數據庫中選擇的行?
con = new SqlConnection("Data Source=LEO-PC\\SQLEXPRESS;Initial Catalog = datashare;Integrated Security = True");
cmd = new SqlCommand("select * from maintable", con);
con.Open();
SqlDataReader sqlRead;
try
{
sqlRead = cmd.ExecuteReader();
while (sqlRead.Read())
{
//Adding to datagrid
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
如果你是初學者,你可能會檢查SQLDataSource控件。 http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.aspx – 2012-08-15 06:30:40