Err: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax

I get this error message in cmd.ExecuteNonQuery()

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '//' at line 1"

when I run the code below. The concept is to read some values from a databse and write the result into another databse if the condition is satisfied.

Dim conString As String

Dim myconn As MySqlConnection

Dim sql As String

conString = "Server=localhost; Database=xyz; Uid=root"

myconn = New MySqlConnection(conString)

 

sql = "Select site_id, timestring, pwr_vin, dsp_dig_in_6 from soh_data order by timestring desc limit 1"

 

Dim mycmd As MySqlCommand = New MySqlCommand(sql, myconn)

myconn.Open()

Dim dr As MySqlDataReader = mycmd.ExecuteReader()

While dr.Read()

Response.Write("Site Id: " & dr.GetInt32(0) & "<br/>" & "Date and Time: " & dr.GetDateTime(1) & "<br/>" & "Data Logger Power:" & dr.GetDouble(2) & "<br/>" & "UPS Power Status:" & dr.GetInt32(3))

If dr.GetDouble(2) < 20 Then

Dim id As Int32 = dr.GetInt32(0)

Dim time As DateTime = dr.GetDateTime(1)

Dim dpower As Double = dr.GetDouble(2)

Dim upower As Int32 = dr.GetInt32(3)

Dim mycon As MySqlConnection = New MySqlConnection("Server=localhost; Database=neadb; Uid=root")

Dim strSQL As String = "Insert into soh_event(site_id,timestring,pwr_vin,dsp_dig_in_6,status)" & _

"values(" & _

id & ", " & _

"#" & time & "#" & ", " & dpower & ", " & upower & ", 'Fail')"

Dim cmd As MySqlCommand = New MySqlCommand(strSQL, mycon)

cmd.Connection.Open()

cmd.ExecuteNonQuery()

cmd.Connection.Close()

End If

dr.Close()

myconn.Close()

End While

I am clueles about this error. Anybody encountered this kind of problem please help.

0
Nithila
5/7/2008 10:00:29 AM
asp.net.mysql 1929 articles. 0 followers. Follow

5 Replies
2878 Views

Similar Articles

[PageSpeed] 59

Dunno exactly which command gives you an error but o  esuggestion:

Use parameterized commands instead of PHP-style SQL query strings. It helps you maintain queries more easily and to avoid SQL-injection attacks.
Don't forget to mark solution providing post as "Answered".
It helps others to find correct solutions!

Also visit my ASP.NET blog!
0
DigiMortal
5/7/2008 10:19:37 AM

Select site_id, timestring, pwr_vin, dsp_dig_in_6 from soh_data order by timestring desc limit 1

 

run this statement art ur database then check the error.


Thanks and Regards
Somnath
Please click “Mark as Answer” on the post if it helps you,
0
Som
5/7/2008 10:22:57 AM

Thanks for the replies.

 

Som Nath Shukla:

Select site_id, timestring, pwr_vin, dsp_dig_in_6 from soh_data order by timestring desc limit 1

 

run this statement art ur database then check the error.

I have no problem with this query. These values are retrived properly and stored in the corresponding variables like id, time  and so on. I checked these variables during debugging and they are passed correctly. It stucks when excuting the ExecuteNonQuery.

What should be the reason?

 

0
Nithila
5/8/2008 12:59:57 AM

I removed the # used to enclose the date with ' and no error message. The values written into the database correctly except the timestring which is a timestamp all zeros.

0
Nithila
5/8/2008 3:55:15 AM

I fixed the problem. It is because of the datetime format mismatch. MySQL expects the datetime format in yyyy-mm-dd hh:mm:ss

I added the extra code as below and the namespace.

<%@ Import Namespace ="Microsoft.VisualBasic" %>

 

Dim time As DateTime = dr.GetDateTime(1)

Dim s As String 'create a string

s = time.ToString("yyyy'-'MM'-'dd HH':'mm':'ss")

 

0
Nithila
5/8/2008 8:16:27 AM
Reply:

Similar Artilces:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
hi,while i executing a query i dot the error message like this "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version"can anyone help me   Can you give any other detail of your configuration? It seems the database path is not properly described.---Pasaban---MCTS...

ERROR [HY000] [MySQL][ODBC 3.51 Driver]Can't connect to MySQL server on 'IP Address of the server'(10048) ERROR [HY000] [MySQL][ODBC 3.51 Driver]Can't connect to MySQL server on 'IP of the server' (10
Hi, I am randomly getting the following error message in my application. ERROR [HY000] [MySQL][ODBC 3.51 Driver]Can't connect to MySQL server on 'IP Address of the server'(10048) ERROR [HY000] [MySQL][ODBC 3.51 Driver]Can't connect to MySQL server on 'IP of the server' (10048) I am using .Net 2.0 with VS2005 having ODBC 3.51.14 Driver.  Can any body point out the core reasons of the above error message? Thanks. Nouman Khawaja. I do have the same problem, help me out. Thanks  If the going seems easy, You are going DownHill... When I was writing ...

Converting SQL syntax to MySQL syntax
 Hi, the following is a stored procedure written for SQL,  would this work in MySQL or do I have to change the syntax? If so would you please point me to the site that will show me how to convert it to one that is equivalent to the MySQL syntax?  Thank you in advance for your help.CREATE PROCEDURE sp_PagedItems    (     @Page int,     @RecsPerPage int    )AS-- We don't want to return the # of rows inserted-- into our temporary table, so turn NOCOUNT ONSET NOCOUNT ON--Create a temporary tableCREATE TABLE ...

VWD 2008 Express Error 42000 MySQL ODBC 5.1 Driver mysqld-5.0.22 error in SQL Syntax
This is driving me a bit mad now trying to get this fixed. Have downloaded and install the mysql connector 5.2.0, have managed to connect fine to the database using ODBC, Can connect ok to the database in Access 2008 and see data.In Visual Web Developer Express 2008 have managed to connect to the database ok, can see all the tables there. However when adding the SqlDataSource and configure, will connect ok, However in the configure the Select Statement it doesn't retreive any of the columns in the specify columns from a table or view. If I do a specify a customer SQL Statement ...

wegconfig connectionstring ADODB System.Data.Odbc error is [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'TSQL'
    <add name="MYADODBCUSTOMERCONNECTIONSTRING" connectionString="Driver={SQL Server};Server=xxx.xxx.xxx.xxx;Database=myDbname;Uid=xxxxx;Pwd=xxxxx" providerName="System.Data.Odbc" />   [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'TSQL'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.COMException: [Micros...

SQL Syntax in DBD::mysql
------=_NextPart_000_000D_01C263B6.FA136D10 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I am trying to use the following code to insert data into a mysql = database:- # write the information to the database $sth=3D$dbh->prepare("INSERT INTO = images(name,desc,category,subcat1,subcat2,image) VALUES(?,?,?,?,?,?)"); $sth->bind_param(1,$name); $sth->bind_param(2,$desc); $sth->bind_param(3,$category); $sth->bind_param(4,$subcat1); $sth->bind_param(5,$subcat2); $sth->bind_param(6,$photo); ...

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql/mysql.soc
2 day old install of 11.3; I installed MYSQL from yast2; 12 items relating to MYSQL are shown as installed; on a command line (as root) I get "ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql/mysql.soc" when I type MYSQL. Another problem ; Apache is installed and running, but my install of PHP from Yast has been troubled, and very much unlike what I read here : "http://www.novell.com/coolsolutions/feature/595.html" ; a web page with phpinfo() shows nothing; do I have to do another manual config of LAMP ? If so wh...

Select error: SQLSTATE = 37000 [Microsoft][ODBC SQL Server Driver]Syntax error or access violation
EAS 3.61 C2 with PB 7.03 components, datawindows and nvo's. Powerdynamo 3.5.2. ODBC connection cache that works. This is an application port from a NT 4.0 server to a Window 2000 Server. The whole application works fine, through CORBA and 7 NVO's with at least 20 other datawindows that I have tested. The ONLY offending datawindow causing 'Select error: SQLSTATE = 37000 [Microsoft][ODBC SQL Server Driver]Syntax error or access violation ' is called from a browser **************************************************************************** ********* dwB...

MySQL ERROR 2013 (HY000): Lost connection to MySQL server
I am having a time trying to resolve this issue. It appears to be a bug with the version of MySQL that is included with SLES 11sp1 but support told me they don't support it. Go figure so I thought I would see if anyone on the boards have experienced this issue or could assist me with the issue. I am running SLES 11sp1 with mysql Ver 14.12 Distrib 5.0.67, for suse-linux-gnu (x86_64) using readline 5.2. I have a test database, vs_test, I am using to test out some basic SQL statements. I have found when I run: mysql> insert into `t1` (`d`)select * from `t1` on duplicate key u...

MySQL ERROR 2013 (HY000): Lost connection to MySQL server
I am trying to run this SQL statement on openSUSE 11.2 using mysql Ver 14.14 Distrib 5.1.36, for suse-linux-gnu (x86_64) using readline 6.0 and constantly receive this error message. mysql> select 1 from `emp`,`dep` where `a` <=> (select 1 union select 2) into @`var0`; ERROR 2013 (HY000): Lost connection to MySQL server during query I installed the Enterprise version of MySQL by Oracle on a different machine, same version of SUSE, and this works. I don't want to have to purchase there version and from what I can tell it is only one revision off mysql Ver 14.14 Di...

MYSQL syntax
I have the following statement to extract data from the last 5 years of a table: SELECT `invoice`.`Inv_Num`, `invoice`.`Cust_Num`, `invoice`.`Inv_Date`, `invoice`.`Vat_Rate`, `inv_list`.`Line_ID`, `inv_list`.`Quantity`, `inv_list`.`Sell_price`, `inv_list`.`Line_Total`, `inv_list`.`Description` FROM `invoice` Inner Join `inv_list` ON `invoice`.`Inv_Num` = `inv_list`.`Inv_Num` WHERE `inv_list`.`Description` LIKE '%parking charge%' AND `invoice`.`Inv_Num` > '670' I need to extract each months data and sum the line total. Is there a simple way to do this? ...

My sql syntax for MySQL got problem?
I am trying out dataset. My database is Mysql. I can't seem to preview my data and also a textbox for my to key in something in my parameter. Is there something wrong my sql below? SELECT clinic.* FROM clinic WHERE (state = '@state')My HomePage - www.findingsteve.net"It is more blessed to give than to receive." Acts 20: 35 (NIV, Bible)Progress - "Never discourage anyone...who continually makes progress, no matter how slow." Plato I don't know anything about MySQL, but as far as SQL goes, you would need to remove the single quotes from your WHERE clause as so: SE...

Converting from PHP/MySQL to .NET/SQL Server
Hello W are looking to convert several applications to .NET using SQL Server. I see where the migration assistant can be of great help with most of the code. I was wondering what would be the best approach to covert the SQL database syntax from MYSQL to SQL Server Thanks in advance for your help! Dave It depends on how you would like to do it. There are a few ways to go about it: A) Convert all applicable SQL to stored procedures. B) Convert most, but not all (some might be difficult) to stored procedures and leave the rest as they are. C) Leave them all. If you p...

Sql server syntax error during DataTransformationService export..
I am trying to do the DTS export from SQL server 2000 to spreadsheet.Every single time i am getting the error [Microsoft][ODBC SQL Server Driver][SQL server]Syntax error converting the nvarchar value '1version=9' to a column of datatype int.it retrieved some row,i can see that in preview but it failed at some row number..So to see the exact row or where its stopping i ran the query under view (Databases->DBname->New->View)it retrieved some row and stopped at row with custid 1947 .there are 50000 rows in a table..i changed the query by adding 'AND (dbo.Customer.CustomerId...

Web resources about - Err: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax - asp.net.mysql

Three quarters of Australians believe climate change is real; views on cause correspond with world view ...
Three quarters of Australians believe climate change is happening, but conservative voters are more likely to believe it is a natural phenomenon. ...

Talk on Twitter corresponds to higher TV ratings
A new Nielsen study shows a correlation between people tweeting about a certain TV show and an increase in that show's ratings.

Debris number corresponds to Boeing 777 component - CNN.com
Boeing investigators are confident that debris found on a remote island comes from a 777 aircraft, source says.

Number on Reunion Island debris corresponds to Boeing 777 component
An international team of aviation experts is trying to determine if that airplane part comes from Malaysia Airlines flight 370, a Boeing 777 ...

The Strength Of The Economy Corresponds To How Often We Cut Our Hair
The dearth of split ends sprouting from the heads of Americans means more than that we're obsessed with our looks, it's an indication that our ...

Top EPA official used private email account to correspond with environmental groups
EPA Region 8 Administrator James Martin apparently corresponded with the Environmental Defense Fund

Chipotle Raises SF Prices to Correspond With Wage Hike
Some locations have seen a 14 percent increase.

Wizard Hoodie With Light And Sound Effects That Correspond To Different Spells You Can Cast
The Technomancer 2.0 Digital Wizard Hoodie is a $120 hoodie available from ThinkGeek (previously an April Fools' joke that they made real). The ...

Number Of Twitter Followers Does NOT Correspond To Influence: STUDY
Previously, a person's influence on Twitter was thought to correlate directly to the number of followers. Advertisers even pay popular Tweeters ...

Was 50 Cent's Awful First Pitch A PR Stunt? Blooper Corresponds With New Album 'Animal Ambition' Release ...
Timing of 50 Cent's first pitch before Tuesday night's New York Mets game raises questions about whether the whole incident was a PR stunt.

Resources last updated: 12/30/2015 5:28:21 AM