Update MDB where there's space in header

E

Eran.Yasso

Hi,

My app updates mdb file with no probelm. the problem starts if there's
a space on a column name(header consists from two words). I tried all
sorts of things. here is my code:

private void button1_Click(object sender, System.EventArgs e)
{
string ColumnHeader = "DTV_DOWN MAC",updatestr="myupdate";
System.Data.OleDb.OleDbConnection con = null;
System.Data.OleDb.OleDbCommand command = null;
string filename = @"C:\test.mdb";
DataSet ds = new DataSet();
try
{
con = new
System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" + filename);// + ";Extended
Properties=\"text;HDR=Yes;IMEX=1;FMT=Delimited\"");
string sql = "UPDATE DataTable SET '" + ColumnHeader + "' =
'"+updatestr+"' WHERE TBL_ID = 1980";
con.Open();
command = new OleDbCommand(sql,con);
int t = command.ExecuteNonQuery();
}
catch(Exception err)
{
MessageBox.Show(err.Message.ToString());
}
con.Close();
}

the exception occurs in line int "t = command.ExecuteNonQuery();".
i get error message "No value given for one or more requiered
parameter".
If i remove the space and use "_" in the mdb header and in
ColumnHeader,
it works. Can't I update MDB with space in header?

Thanks for the help.
 
F

ForrestPhoto

My app updates mdb file with no probelm. the problem starts if there's
a space on a column name(header consists from two words). I tried all
sorts of things. here is my code:

In Microsoft ( Access or SQL Server ) you can have spaces in your
column names, but then when you refer to them in a query, you have to
surround them with [ square brackets ].
 
E

Eran.Yasso

My app updates mdb file with no probelm. the problem starts if there's
a space on a column name(header consists from two words). I tried all
sorts of things. here is my code:

In Microsoft ( Access or SQL Server ) you can have spaces in your
column names, but then when you refer to them in a query, you have to
surround them with [ square brackets ].

Thank you. God bless you. If my father was rich i would donate you :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top