日期:2014-05-18 浏览次数:20844 次
private static void ReadOrderData(string connectionString) { string queryString = "SELECT OrderID, CustomerID FROM dbo.Orders;"; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(queryString, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); // Call Read before accessing data. while (reader.Read()) { Console.WriteLine(String.Format("{0}, {1}", reader[0], reader[1])); } // Call Close when done reading. reader.Close(); } }
------解决方案--------------------
SqlDataReader reader = new SqlDataReader(sql, conn);
改成
OleDbCommand cmd=new OleDbCommand(sql.conn);
OleDbDataReader reader=cmd.ExecuteReader();
------解决方案--------------------
string strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\db1.mdb;";
OleDbConnection conn = new OleDbConnection(strconn);
conn.Open();
string sql = "select [Time] from [project] where [Name]='" + DropDownList1.SelectedValue + "'";
OleDbCommand cmd=new OleDbCommand(sql.conn);
OleDbDataReader reader=cmd.ExecuteReader();
if (reader.Read())
{
TextBox3.Text = reader[0].ToString();
}
conn.Close();