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