I wrote a program that inserts records into a table in a MS Access
database. For some reason, it works only for tables without spaces in
their names:

There are four tables: "test 1" "test2" "test 3" and "test4" each with
fields word, pos, and meaning.

The following code works only for test2 and test4, the tables whose
names do not contain any spaces.

string tableName="test 1"; //place table name here
OleDbConnection conn=new
OleDbConnection("provider=microsoft.jet.oledb.4.0;data
source=lists.mdb");
OleDbDataAdapter da=new OleDbDataAdapter("select * from
["+tableName+"]",conn);
OleDbCommandBuilder cb=new OleDbCommandBuilder(da);
DataSet ds=new DataSet();
da.Fill(ds);
conn.Close();

DataTable dt=ds.Tables[0];
DataRow dr=dt.NewRow();
dr["word"]="myword";
dr["pos"]="mypos";
dr["meaning"]="mymeaning";
dt.Rows.Add(dr);
try
{
da.Update(ds);
}
catch(OleDbException ole){Console.WriteLine(ole.Message);}

Re: Table Names with Spaces by Bernie

Bernie
Tue Jan 06 19:33:46 CST 2004

Hi,

Refer to tables with spaces by using brackets: test2 but [test 3]

HTH,

Bernie Yaeger

"AnandVishy" <choketsu2@hotmail.com> wrote in message
news:8e03e77.0401061728.2ab9fbac@posting.google.com...
> I wrote a program that inserts records into a table in a MS Access
> database. For some reason, it works only for tables without spaces in
> their names:
>
> There are four tables: "test 1" "test2" "test 3" and "test4" each with
> fields word, pos, and meaning.
>
> The following code works only for test2 and test4, the tables whose
> names do not contain any spaces.
>
> string tableName="test 1"; //place table name here
> OleDbConnection conn=new
> OleDbConnection("provider=microsoft.jet.oledb.4.0;data
> source=lists.mdb");
> OleDbDataAdapter da=new OleDbDataAdapter("select * from
> ["+tableName+"]",conn);
> OleDbCommandBuilder cb=new OleDbCommandBuilder(da);
> DataSet ds=new DataSet();
> da.Fill(ds);
> conn.Close();
>
> DataTable dt=ds.Tables[0];
> DataRow dr=dt.NewRow();
> dr["word"]="myword";
> dr["pos"]="mypos";
> dr["meaning"]="mymeaning";
> dt.Rows.Add(dr);
> try
> {
> da.Update(ds);
> }
> catch(OleDbException ole){Console.WriteLine(ole.Message);}



Re: Table Names with Spaces by William

William
Tue Jan 06 21:13:27 CST 2004

Yes, but do yourself (and the people that inherit your code) get rid of all
embedded spaces in object names. Lots of tools don't work well with them and
you'll be tripping over this problem forever.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"Bernie Yaeger" <berniey@cherwellinc.com> wrote in message
news:O7KNK5L1DHA.2604@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> Refer to tables with spaces by using brackets: test2 but [test 3]
>
> HTH,
>
> Bernie Yaeger
>
> "AnandVishy" <choketsu2@hotmail.com> wrote in message
> news:8e03e77.0401061728.2ab9fbac@posting.google.com...
> > I wrote a program that inserts records into a table in a MS Access
> > database. For some reason, it works only for tables without spaces in
> > their names:
> >
> > There are four tables: "test 1" "test2" "test 3" and "test4" each with
> > fields word, pos, and meaning.
> >
> > The following code works only for test2 and test4, the tables whose
> > names do not contain any spaces.
> >
> > string tableName="test 1"; //place table name here
> > OleDbConnection conn=new
> > OleDbConnection("provider=microsoft.jet.oledb.4.0;data
> > source=lists.mdb");
> > OleDbDataAdapter da=new OleDbDataAdapter("select * from
> > ["+tableName+"]",conn);
> > OleDbCommandBuilder cb=new OleDbCommandBuilder(da);
> > DataSet ds=new DataSet();
> > da.Fill(ds);
> > conn.Close();
> >
> > DataTable dt=ds.Tables[0];
> > DataRow dr=dt.NewRow();
> > dr["word"]="myword";
> > dr["pos"]="mypos";
> > dr["meaning"]="mymeaning";
> > dt.Rows.Add(dr);
> > try
> > {
> > da.Update(ds);
> > }
> > catch(OleDbException ole){Console.WriteLine(ole.Message);}
>
>



Re: Table Names with Spaces by Miha

Miha
Wed Jan 07 04:01:59 CST 2004

Hi Bill,

Ditto.

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"William (Bill) Vaughn" <billvaRemoveThis@nwlink.com> wrote in message
news:OIFB5wM1DHA.2184@TK2MSFTNGP12.phx.gbl...
> Yes, but do yourself (and the people that inherit your code) get rid of
all
> embedded spaces in object names. Lots of tools don't work well with them
and
> you'll be tripping over this problem forever.