0

I am trying to read some data from a db but I am getting an error on oledbdatareader.

here is my code.

OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Power User\Desktop\Domains.accdb;Persist Security Info=False");
            conn.Open();
            OleDbCommand cmd = new OleDbCommand();
            cmd.Connection = conn;
            //cmd.CommandText = "Select * from Domains";
            cmd.CommandText = "Select * FROM Domains WHERE Domain= '" + TextBox1.Text + "'";
            OleDbDataReader dr = cmd.ExecuteReader();
            GridView1.DataSource = dr;
            GridView1.DataBind();
            conn.Close();

Edited by azfarhus: n/a

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by PierlucSS
0

Try putting square bracers around any table and field names (eg "[Domains]"); I'm not sure about the database you are using, but i know some database standards have DOMAIN as a reserved word.

0

^ thanks, it worked.

If your satisfied with the answer, please flag this as solved (bottom of the page)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.