By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,869 Members | 1,756 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,869 IT Pros & Developers. It's quick & easy.

Why can't the "+" operator work with a string variable to concaten

P: n/a
Hi, I want to concatenate a string variable (containing file path and name)
to a sqlcommnad text string but I'm getting error about "+" can't be used
with string operand. It's very odd. What am I doing wrong?

Thanks, Alpha

try
{//@"C:\\VMS\\VMSDB"
string[] ATSFiles = Directory.GetFiles(@strATSPath, "Ats*Db.mdb");
Array.Sort(ATSFiles);
NewATS= ATSFiles[ATSFiles.Length - 1];
}
catch(Exception ex)
{
MessageBox.Show("Error getting the ATS Access database files : " +
ex.ToString()+
"Please contact your support person.", "VMS - ATS files Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}

try
{
//Insert new vehicle from the ATS Access database
scUpdate.CommandText = "INSERT INTO VehDetail(VName, LastOdometerDate,
LastOdometerReading)"+
" SELECT [d_RemoteName],MAX([d_DateTime]), MAX([d_OdometerTenths])"+
" FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',"+
+ @NewATS + "';'Admin';'', DATA)"+
" WHERE [d_RemoteName] NOT IN(SELECT VNAME FROM VehDetail)"+
" GROUP BY [d_RemoteName]";
int row = scUpdate.ExecuteNonQuery();
Nov 17 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
It might be having a problem with @NewATS since this is not quoted or
anything and I would imaging that "@" is not a valid variable character.
Just a guess though.

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:83**********************************@microsof t.com...
Hi, I want to concatenate a string variable (containing file path and
name)
to a sqlcommnad text string but I'm getting error about "+" can't be used
with string operand. It's very odd. What am I doing wrong?

Thanks, Alpha

try
{//@"C:\\VMS\\VMSDB"
string[] ATSFiles = Directory.GetFiles(@strATSPath, "Ats*Db.mdb");
Array.Sort(ATSFiles);
NewATS= ATSFiles[ATSFiles.Length - 1];
}
catch(Exception ex)
{
MessageBox.Show("Error getting the ATS Access database files : " +
ex.ToString()+
"Please contact your support person.", "VMS - ATS files Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}

try
{
//Insert new vehicle from the ATS Access database
scUpdate.CommandText = "INSERT INTO VehDetail(VName, LastOdometerDate,
LastOdometerReading)"+
" SELECT [d_RemoteName],MAX([d_DateTime]), MAX([d_OdometerTenths])"+
" FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',"+
+ @NewATS + "';'Admin';'', DATA)"+
" WHERE [d_RemoteName] NOT IN(SELECT VNAME FROM VehDetail)"+
" GROUP BY [d_RemoteName]";
int row = scUpdate.ExecuteNonQuery();

Nov 17 '05 #2

P: n/a
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',"+ + @NewATS + "';'Admin';'',
DATA)"+
---------------------------------------------------------^
--

Derek Davis
dd******@gmail.com

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:83**********************************@microsof t.com...
Hi, I want to concatenate a string variable (containing file path and
name)
to a sqlcommnad text string but I'm getting error about "+" can't be used
with string operand. It's very odd. What am I doing wrong?

Thanks, Alpha

try
{//@"C:\\VMS\\VMSDB"
string[] ATSFiles = Directory.GetFiles(@strATSPath, "Ats*Db.mdb");
Array.Sort(ATSFiles);
NewATS= ATSFiles[ATSFiles.Length - 1];
}
catch(Exception ex)
{
MessageBox.Show("Error getting the ATS Access database files : " +
ex.ToString()+
"Please contact your support person.", "VMS - ATS files Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}

try
{
//Insert new vehicle from the ATS Access database
scUpdate.CommandText = "INSERT INTO VehDetail(VName, LastOdometerDate,
LastOdometerReading)"+
" SELECT [d_RemoteName],MAX([d_DateTime]), MAX([d_OdometerTenths])"+
" FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',"+
+ @NewATS + "';'Admin';'', DATA)"+
" WHERE [d_RemoteName] NOT IN(SELECT VNAME FROM VehDetail)"+
" GROUP BY [d_RemoteName]";
int row = scUpdate.ExecuteNonQuery();

Nov 17 '05 #3

P: n/a
Bleh stupid wrapping...

('Microsoft.Jet.OLEDB.4.0',"+ + @NewATS + "';'Admin';'', DATA)
-------------------------------^
--

Derek Davis
dd******@gmail.com

"carion1" <dd******@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',"+ + @NewATS + "';'Admin';'',
DATA)"+
---------------------------------------------------------^
--

Derek Davis
dd******@gmail.com

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:83**********************************@microsof t.com...
Hi, I want to concatenate a string variable (containing file path and
name)
to a sqlcommnad text string but I'm getting error about "+" can't be used
with string operand. It's very odd. What am I doing wrong?

Thanks, Alpha

try
{//@"C:\\VMS\\VMSDB"
string[] ATSFiles = Directory.GetFiles(@strATSPath, "Ats*Db.mdb");
Array.Sort(ATSFiles);
NewATS= ATSFiles[ATSFiles.Length - 1];
}
catch(Exception ex)
{
MessageBox.Show("Error getting the ATS Access database files : " +
ex.ToString()+
"Please contact your support person.", "VMS - ATS files Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}

try
{
//Insert new vehicle from the ATS Access database
scUpdate.CommandText = "INSERT INTO VehDetail(VName, LastOdometerDate,
LastOdometerReading)"+
" SELECT [d_RemoteName],MAX([d_DateTime]), MAX([d_OdometerTenths])"+
" FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',"+
+ @NewATS + "';'Admin';'', DATA)"+
" WHERE [d_RemoteName] NOT IN(SELECT VNAME FROM VehDetail)"+
" GROUP BY [d_RemoteName]";
int row = scUpdate.ExecuteNonQuery();


Nov 17 '05 #4

P: n/a
LOL. Thats what I get for trying to be cute. You have ++ after
OLEDB.4.0',"

FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',"+ + @NewATS + "';'Admin';'',
DATA)"+

--

Derek Davis
dd******@gmail.com

"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
It might be having a problem with @NewATS since this is not quoted or
anything and I would imaging that "@" is not a valid variable character.
Just a guess though.

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:83**********************************@microsof t.com...
Hi, I want to concatenate a string variable (containing file path and
name)
to a sqlcommnad text string but I'm getting error about "+" can't be used
with string operand. It's very odd. What am I doing wrong?

Thanks, Alpha

try
{//@"C:\\VMS\\VMSDB"
string[] ATSFiles = Directory.GetFiles(@strATSPath, "Ats*Db.mdb");
Array.Sort(ATSFiles);
NewATS= ATSFiles[ATSFiles.Length - 1];
}
catch(Exception ex)
{
MessageBox.Show("Error getting the ATS Access database files : " +
ex.ToString()+
"Please contact your support person.", "VMS - ATS files Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}

try
{
//Insert new vehicle from the ATS Access database
scUpdate.CommandText = "INSERT INTO VehDetail(VName, LastOdometerDate,
LastOdometerReading)"+
" SELECT [d_RemoteName],MAX([d_DateTime]), MAX([d_OdometerTenths])"+
" FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',"+
+ @NewATS + "';'Admin';'', DATA)"+
" WHERE [d_RemoteName] NOT IN(SELECT VNAME FROM VehDetail)"+
" GROUP BY [d_RemoteName]";
int row = scUpdate.ExecuteNonQuery();


Nov 17 '05 #5

P: n/a
I tried without the @ and it still gives the same error message.

"Peter Rilling" wrote:
It might be having a problem with @NewATS since this is not quoted or
anything and I would imaging that "@" is not a valid variable character.
Just a guess though.

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:83**********************************@microsof t.com...
Hi, I want to concatenate a string variable (containing file path and
name)
to a sqlcommnad text string but I'm getting error about "+" can't be used
with string operand. It's very odd. What am I doing wrong?

Thanks, Alpha

try
{//@"C:\\VMS\\VMSDB"
string[] ATSFiles = Directory.GetFiles(@strATSPath, "Ats*Db.mdb");
Array.Sort(ATSFiles);
NewATS= ATSFiles[ATSFiles.Length - 1];
}
catch(Exception ex)
{
MessageBox.Show("Error getting the ATS Access database files : " +
ex.ToString()+
"Please contact your support person.", "VMS - ATS files Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}

try
{
//Insert new vehicle from the ATS Access database
scUpdate.CommandText = "INSERT INTO VehDetail(VName, LastOdometerDate,
LastOdometerReading)"+
" SELECT [d_RemoteName],MAX([d_DateTime]), MAX([d_OdometerTenths])"+
" FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',"+
+ @NewATS + "';'Admin';'', DATA)"+
" WHERE [d_RemoteName] NOT IN(SELECT VNAME FROM VehDetail)"+
" GROUP BY [d_RemoteName]";
int row = scUpdate.ExecuteNonQuery();


Nov 17 '05 #6

P: n/a
Gees........ After you point it out it still took me another 10 minuttes to
SEE the extra "+". Thank you very much.

"carion1" wrote:
Bleh stupid wrapping...

('Microsoft.Jet.OLEDB.4.0',"+ + @NewATS + "';'Admin';'', DATA)
-------------------------------^
--

Derek Davis
dd******@gmail.com

"carion1" <dd******@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',"+ + @NewATS + "';'Admin';'',
DATA)"+
---------------------------------------------------------^
--

Derek Davis
dd******@gmail.com

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:83**********************************@microsof t.com...
Hi, I want to concatenate a string variable (containing file path and
name)
to a sqlcommnad text string but I'm getting error about "+" can't be used
with string operand. It's very odd. What am I doing wrong?

Thanks, Alpha

try
{//@"C:\\VMS\\VMSDB"
string[] ATSFiles = Directory.GetFiles(@strATSPath, "Ats*Db.mdb");
Array.Sort(ATSFiles);
NewATS= ATSFiles[ATSFiles.Length - 1];
}
catch(Exception ex)
{
MessageBox.Show("Error getting the ATS Access database files : " +
ex.ToString()+
"Please contact your support person.", "VMS - ATS files Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}

try
{
//Insert new vehicle from the ATS Access database
scUpdate.CommandText = "INSERT INTO VehDetail(VName, LastOdometerDate,
LastOdometerReading)"+
" SELECT [d_RemoteName],MAX([d_DateTime]), MAX([d_OdometerTenths])"+
" FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',"+
+ @NewATS + "';'Admin';'', DATA)"+
" WHERE [d_RemoteName] NOT IN(SELECT VNAME FROM VehDetail)"+
" GROUP BY [d_RemoteName]";
int row = scUpdate.ExecuteNonQuery();



Nov 17 '05 #7

P: n/a
" FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',"+
+ @NewATS + "';'Admin';'', DATA)"+

You have two pluses in a row.
Nov 17 '05 #8

P: n/a
As odd as it sounds "@" really is a valid character in a variable
identifier. It allows you to use reserved keywords as variable names.
I haven't really seen a compelling reason to use it though.

Brian

Peter Rilling wrote:
It might be having a problem with @NewATS since this is not quoted or
anything and I would imaging that "@" is not a valid variable character.
Just a guess though.


Nov 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.