Hey. I am fairly new to VB.NET so I research alot when I run into bugs. Problem is I cannot find a solution to this, or anything remotely dealing with it.
I am developing software to connect to a remote mysql server, run a query, and come back with a dataset. I have run this query against the server through a mysql prompt and have received a result successfully. But when i try to run this query from my app, I get an object reference error.
Through debugging I have found that the @ character used for variables in sql strings, is causing the problem in my code, but i cannot find a way to pass this query to the server without visual studio throwing errors.
Here is a bit of my code and my query:
Dim mysqlCon As MySqlConnection = New MySqlConnection("Server=" & arrArgs & ";Database=DBNAME;Uid=USER;Pwd=PASS;allow zero datetime=true;")
Dim mysqlString As String = "set @from_scanner = '" & code & "'; set @code='', @altbarcode='', @qty='1', @price='',@Altprice='0', @date_start='',@date_end='',@disc_price='0',@description='', @altdescription=''; set @from_scanner=if(left(@from_scanner,2)='FF',trim(substring(@from_Scanner,3,13)),trim(substring(@from_Scanner,2,13))); select code, altbarcode,description, qty, price into @code, @altbarcode,@altdescription, @qty, @Altprice from altbar where altbarcode=@from_scanner; set @code=if(@code='',@from_Scanner,@code); select disc_price, date_end into @disc_price, @date_end from plu where (code=trim(left(@code,12)) or def_barcode=@code) and current_date between date_start and date_end and disc_price<>price and disc_price<>0; select price, description into @price, @description from plu where code=trim(left(@code,12)) or def_barcode=@code; set @price=if(ifnull(@disc_price,0)=0 or @disc_price='', @price,@disc_price); set @price=if(@qty>1 and @Altprice > 0, @Altprice, @price*@qty); set @description=if(@altdescription<>'', @Altdescription, @description); select @code, format(@price,2) Price, @description,@date_end;"
Dim mysqlCom As MySqlCommand = New MySqlCommand(mysqlstring, mysqlCon)
Dim mysqlAdapter As New MySqlDataAdapter
Dim mysqlData As New DataSet
mysqlCon.Open()
mysqlAdapter.SelectCommand = mysqlCom
mysqlAdapter.Fill(mysqlData, "tblDBData")
So what I really need to know is how to pass this query on to the mysql server without causing problems in VB.
Thanks in advance
Hersch