473,378 Members | 1,122 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

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
8 1622
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
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
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
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
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
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
" FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',"+
+ @NewATS + "';'Admin';'', DATA)"+

You have two pluses in a row.
Nov 17 '05 #8
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jet | last post by:
Hi all, There is a problem about single sign on not base on SharePoint . There are different web base application in my network group and all of them are not develop by the same technology, such...
2
by: Nathan Pinno | last post by:
Hi, Can anyone tell me if pygame and Tkinter can work together in the same application? I thought I'd better ask before trying it, since both use widgets. Thanks, Nathan Pinno --
0
by: ice godwater via .NET 247 | last post by:
(Type your message here) I created a Web Service with SSL ,my remote WinForm can work well with it ,but the remote WebFrom can't work. -------------------------------- From: ice godwater ...
8
by: Scorpio | last post by:
Hi all, I found the simple program below, no error, no warning. But it can work with no output. Does anyone know why? int main() { 0; }
15
by: jjh | last post by:
So with infile I have this so far: #define MAXBOOKS 9 ifstream infile("library.txt"); struct Book { title } while(true) {
27
by: fdu.xiaojf | last post by:
Hi, String formatting can be used to converting an integer to its octal or hexadecimal form: '307' 'c7' But, can string formatting be used to convert an integer to its binary form ?
6
by: vl106 | last post by:
A static code analysis tool gave me a warning on if (ptr && ptr->data) { ... } I assumed the tool doesn't get the "short circuit behaviour" in the if statement. But a collegue said it may...
7
by: vvkl | last post by:
I have readed a example code from MSDN about FormsAuthenticationTicket calss, but there's a line I can't understand : 'strRedirect = Request;' What's the mean in which square brackets? Thank...
4
by: Jm lists | last post by:
Please help with this script: class ShortInputException(Exception): '''A user-defined exception class.''' def __init__(self,length,atleast): Exception.__init__(self) self.length=length...
12
SammyB
by: SammyB | last post by:
I'm trying to keep up with you youngsters, so I'm taking a beginning Java course. As part of a homework assignment, we were to prompt the user for a number between 1 & 3. We also used while loops...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.