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