there are a few differences between application and asp.net, below I am presenting code which I am using to access file and everything works fine. Try it and let me know if it will be ok
declare connection in web.config file (something like that)
GridView1.DataBind() worked. I will have to learn how to format the gridview as it spanded over the entire page and some of the columns could not be seen.
NewToDotyNet
Member
3 Points
41 Posts
GridView dbf
Dec 21, 2012 11:15 AM|LINK
Hi,
I am attempting to duplicate code from an application to ASP.NET.
The dbf file is on the server along with the pages etc.
In the code below I am not sure how to write the path to address the file. ~/ ????
(Type = "variable" file name = variable.dbf).
(Also I presuning what I am trying to do can be done. i.e. ODBC).
private void cmdViewDBF(string Type)
{
//Connection Via ODBC
OdbcConnection conn = new OdbcConnection();
conn.ConnectionString = "Driver={Microsoft dBASE Driver (*.dbf)};" + "Driverid=277;" +
//"Dbq=C:\\ProgramData\\Citect\\CitectSCADA 7.10\\User\\BEENLEIGH"; This is what it used to be in application
"Dbq=~/"; //Not sure what I should put here???????? - File is on server.
conn.Open();
string consulta = "Select * from " + Type;
OdbcDataAdapter adapter = new OdbcDataAdapter(consulta, conn);
DataSet ds = new DataSet();
adapter.Fill(ds);
conn.Close();
this.GridView1.DataSource = ds.Tables[0];
}
kszymaniak
Member
205 Points
112 Posts
Re: GridView dbf
Dec 21, 2012 12:39 PM|LINK
Hi,
there are a few differences between application and asp.net, below I am presenting code which I am using to access file and everything works fine. Try it and let me know if it will be ok
declare connection in web.config file (something like that)
<connectionStrings> <add name="szymonConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\Documents and Settings\KrzysztofSzymaniak\Moje dokumenty\szymon.mdb';" providerName="System.Data.OleDb" /> </connectionStrings>in code please use for connect to database
and remaining as yr post
Regards
PS. you can declare connection and bind data in gridview with GridView Tasks (GridView Properies) -> Choose Data Source -> New data source
NewToDotyNet
Member
3 Points
41 Posts
Re: GridView dbf
Dec 22, 2012 01:04 AM|LINK
Hi,
this shows the web page and has no errors. Except the GridView1 is not displayed.
private void cmdViewDBF(string Type) {
//Connection Via ODBC
OdbcConnection conn = new OdbcConnection();
conn.ConnectionString = "Driver={Microsoft dBASE Driver (*.dbf)};" + "Driverid=277;" + "Dbq=" + Server.MapPath("~/");
conn.Open();
string consulta = "Select * from " + Type;
OdbcDataAdapter adapter = new OdbcDataAdapter(consulta, conn);
DataSet ds = new DataSet();
adapter.Fill(ds);
conn.Close();
this.GridView1.DataSource = ds.Tables[0];
this.GridView1.Visible = true;
}
Thanks,
Anil Srivast...
Member
442 Points
292 Posts
Re: GridView dbf
Dec 22, 2012 01:43 AM|LINK
http://www.connectionstrings.com/access
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: GridView dbf
Dec 22, 2012 02:48 AM|LINK
Hi
Please add GridView1.DataBind() directly at the back of GridView.Visible=true.
NewToDotyNet
Member
3 Points
41 Posts
Re: GridView dbf
Dec 22, 2012 03:59 AM|LINK
Hi,
GridView1.DataBind() worked. I will have to learn how to format the gridview as it spanded over the entire page and some of the columns could not be seen.
Thanks,
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: GridView dbf
Dec 22, 2012 04:02 AM|LINK
Hi,
You can use CSS by assigning to ItemStyle or GridViewStyle.