using (SqlConnection conn = new SqlConnection(connectionString) ) { conn.Open(); SqlCommand cmd = new SqlCommand("select * from tb where 1=1", conn); SqlDataAdapter adapter = new SqlDataAdapter(cmd ); DataTable dataTable = new DataTable(); adapter.Fill(dataTable); }
string A= dt.Rows["第X行"]["x"].ToString();
string B= dt.Rows["第X行"]["y"].ToString();Rows[] 索引从0开始 既 第一行为:dt.Rows[0]
for(int i=0;i<dt.rows.count;i++)
{
string A= dt.Rows[i]["x"].ToString();
string B= dt.Rows[i]["y"].ToString();
}
{
conn.Open();
SqlCommand cmd = new SqlCommand("select * from tb where 1=1", conn);
SqlDataAdapter adapter = new SqlDataAdapter(cmd );
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
}