[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

Write a text file using new ODBC Managed Provider

Ron Teal

3/11/2002 8:03:00 PM

I'm wondering if anyone has "updated" a text file using
the new .NET ODBC Managed Provider. I can read data from
a text file fine but would also like to be able to update
fields within the file. Here's some code I've been
tinkering with...


private DataSet Build ( DataSet ds )
{
DataTable dt = new DataTable ( "RazorNames" );
dt.Columns.Add ( new DataColumn ( "ID", typeof ( int ) ) );
dt.Columns.Add ( new DataColumn ( "First", typeof (
string ) ) );
dt.Columns.Add ( new DataColumn ( "Last", typeof (
string ) ) );
DataColumn [ ] pk = new DataColumn[1];
pk[0] = dt.Columns ["ID"];
dt.PrimaryKey = pk;
ds.Tables.Add ( dt );
return ds;
}

private void button1_Click
(object sender, System.EventArgs e)
{

OdbcConnection conn =
new OdbcConnection( "Provider=MSDASQL.1;DSN=RazorFile;" );
OdbcCommand selectCMD = new OdbcCommand ( );
selectCMD.CommandType = CommandType.Text;
selectCMD.CommandText = "SELECT ID, First, Last FROM
RazorDatabaseFile.txt";
selectCMD.Connection = conn;
OdbcDataAdapter da = new OdbcDataAdapter ( );
da.SelectCommand = selectCMD;
DataSet ds = new DataSet ( );
ds = Build ( ds );
da.Fill( ds, "RazorNames" );
OdbcCommandBuilder cb = new OdbcCommandBuilder ( da );
dataGrid1.SetDataBinding( ds , "RazorNames" );
//ds.Tables["RazorNames"].Rows[0]["First"] = "Ronald";
//da.Update ( ds, "RazorNames" );
}


I'm beginning to suspect there's something about the
provider that I don't have setup properly. When I try to
run a SQL update command as follows ...

UPDATE RazorDatabaseFile.txt
SET First = 'Ronald'

From the Server Explorer environment I get the following
error description...

"[Microsoft][ODBC Text Driver] Updating data in a linked
table is not supported by this ISAM."

Help and comments would be greatly appreciated.

Thanks,
Ron Teal
5 Answers

(Steven Bras [MS])

3/15/2002 10:04:00 PM

0

Ron Teal

3/15/2002 11:27:00 PM

0

Steven...Thanks for the response.
I'll fix my connection string.

Ron Teal

>-----Original Message-----
>Our text driver (ISAM) does not support updating
individual fields or
>deleting rows; the only operation permitted is to add a
complete row.
>
>Also, for your ODBC connection string, do not
use "provider=msdasql;". This
>is the OLEDB provider for ODBC drivers and is not
necessary. Remove that
>portion of the connection string when using ODBC. And do
not use it with
>System.Data.Oledb; it's not supported.
>
>I regret I can't post a more positive response to your
problem. Good luck!
>
>Steven Bras, MCSD
>Microsoft Developer Support/Visual Basic WebData
>
>This posting is provided "AS IS" with no warranties, and
confers no rights.
>
>Are you secure? For information about the Microsoft
Strategic Technology
>Protection Program and to order your FREE Security Tool
Kit, please visit
>http://www.microsoft.co....

Ron Teal

3/18/2002 3:50:00 PM

0

The following code worked for inserting a new "row" in the
file...

private void button1_Click
(object sender, System.EventArgs e)
{

OdbcConnection conn = new OdbcConnection
( "DSN=RazorFile;" );

OdbcCommand selectCMD = new OdbcCommand ( );
selectCMD.CommandType = CommandType.Text;
selectCMD.CommandText = "SELECT ID, First, Last FROM
RazorDatabaseFile.txt";
selectCMD.Connection = conn;

OdbcDataAdapter da = new OdbcDataAdapter ( );
da.SelectCommand = selectCMD;

DataSet ds = new DataSet ( );
ds = Build ( ds );
da.Fill( ds, "RazorNames" );

dataGrid1.SetDataBinding( ds , "RazorNames" );

OdbcCommandBuilder cb = new OdbcCommandBuilder ( da );

// Attempt to insert a row in the file
RazorDatabaseFile.txt
//
DataRow dr = ds.Tables["RazorNames"].NewRow( );
dr["ID"] = 777;
dr["First"] = "Gomer";
dr["Last"] = "Pyle";
ds.Tables["RazorNames"].Rows.Add ( dr );
da.Update ( ds, "RazorNames" );

}

Ron Teal

>-----Original Message-----
>Steven...Thanks for the response.
>I'll fix my connection string.
>
>Ron Teal
>
>>-----Original Message-----
>>Our text driver (ISAM) does not support updating
>individual fields or
>>deleting rows; the only operation permitted is to add a
>complete row.
>>
>>Also, for your ODBC connection string, do not
>use "provider=msdasql;". This
>>is the OLEDB provider for ODBC drivers and is not
>necessary. Remove that
>>portion of the connection string when using ODBC. And do
>not use it with
>>System.Data.Oledb; it's not supported.
>>
>>I regret I can't post a more positive response to your
>problem. Good luck!
>>
>>Steven Bras, MCSD
>>Microsoft Developer Support/Visual Basic WebData
>>
>>This posting is provided "AS IS" with no warranties, and
>confers no rights.
>>
>>Are you secure? For information about the Microsoft
>Strategic Technology
>>Protection Program and to order your FREE Security Tool
>Kit, please visit
>>http://www.microsoft.co....
>.
>

(Steven Bras [MS])

3/18/2002 6:07:00 PM

0

Heng Ma

3/26/2002 8:46:00 PM

0

Hi, Ron

I'm not able to make your code work here. Here are the seetings that I
used:

1. DSN set with "Microsoft Text Driver (*.txt, *.csv).
2. Project References added "Microsoft.Data.Odbc".
3. Project "using Microsoft.Data.Odbc;"
4. Text file format "1 FistName LastName" per line.

Would you please point me where I'm doing worng?

Thanks,

-- Heng

"Ron Teal" <ron.teal@tbe.com> wrote in message
news:2ed401c1ce8c$43e503b0$3def2ecf@TKMSFTNGXA14...
> The following code worked for inserting a new "row" in the
> file...
>
> private void button1_Click
> (object sender, System.EventArgs e)
> {
>
> OdbcConnection conn = new OdbcConnection
> ( "DSN=RazorFile;" );
>
> OdbcCommand selectCMD = new OdbcCommand ( );
> selectCMD.CommandType = CommandType.Text;
> selectCMD.CommandText = "SELECT ID, First, Last FROM
> RazorDatabaseFile.txt";
> selectCMD.Connection = conn;
>
> OdbcDataAdapter da = new OdbcDataAdapter ( );
> da.SelectCommand = selectCMD;
>
> DataSet ds = new DataSet ( );
> ds = Build ( ds );
> da.Fill( ds, "RazorNames" );
>
> dataGrid1.SetDataBinding( ds , "RazorNames" );
>
> OdbcCommandBuilder cb = new OdbcCommandBuilder ( da );
>
> // Attempt to insert a row in the file
> RazorDatabaseFile.txt
> //
> DataRow dr = ds.Tables["RazorNames"].NewRow( );
> dr["ID"] = 777;
> dr["First"] = "Gomer";
> dr["Last"] = "Pyle";
> ds.Tables["RazorNames"].Rows.Add ( dr );
> da.Update ( ds, "RazorNames" );
>
> }
>
> Ron Teal
>
> >-----Original Message-----
> >Steven...Thanks for the response.
> >I'll fix my connection string.
> >
> >Ron Teal
> >
> >>-----Original Message-----
> >>Our text driver (ISAM) does not support updating
> >individual fields or
> >>deleting rows; the only operation permitted is to add a
> >complete row.
> >>
> >>Also, for your ODBC connection string, do not
> >use "provider=msdasql;". This
> >>is the OLEDB provider for ODBC drivers and is not
> >necessary. Remove that
> >>portion of the connection string when using ODBC. And do
> >not use it with
> >>System.Data.Oledb; it's not supported.
> >>
> >>I regret I can't post a more positive response to your
> >problem. Good luck!
> >>
> >>Steven Bras, MCSD
> >>Microsoft Developer Support/Visual Basic WebData
> >>
> >>This posting is provided "AS IS" with no warranties, and
> >confers no rights.
> >>
> >>Are you secure? For information about the Microsoft
> >Strategic Technology
> >>Protection Program and to order your FREE Security Tool
> >Kit, please visit
> >>http://www.microsoft.co....
> >.
> >