0
저는 C# 프로그래머입니다. 현재, 나는 datagrid - 뷰어의 SQL 데이터에 5 열 중 3 개 (fileId, filePath, authorName, fileContent, DateSend)를 추가하려고합니다. fileId 및 fileContent 열은 숨겨집니다. 고마워요!datagridview는 SQL 데이터베이스에서 선택된 행을 표시합니까?
SqlDataReader reader = cmd.ExecuteReader();
gridView1.DataSource = reader;
를 사용하여 그리드를 채우는 기억
OnRowCreated = "gridView1_RowCreated"
:
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 –