Dim mysqlconnectionstring As String = "server = server; database=database; uid=uid; pwd=pwd;connect timeout=30;"
Dim myadoconnection As New MySqlConnection()
Hi, i have this above code in class.vb... i'm doing a website project. i would need to do a connection to database in order for me to insert data into the database.
but when i have "myadoconnection.connectionstring = mysqlconnectionstring", the word in bold gave me error... "Declaration Expected" but i already declared it on the second line.
i'm stuck. please help me... i really appreciate it very much... thank you :)
I have never used the MySql provider so I probably can't help you much there.
I run this code in VS 2005 with no problems so your problem might be with the MySql provider?
Imports System.Data.SqlClient
Partial Class Default11
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim mysqlconnectionstring As String = "server = server; database=database; uid=uid; pwd=pwd;connect timeout=30;"
Dim myadoconnection As New SqlConnection()
myadoconnection.ConnectionString = mysqlconnectionstring
myadoconnection.open()
End Sub
End Class
Hi.. realise one thing. as mention with the code that you put in, i change to mysqlclient. and is okie... so probably i can't do it in class.vb... because i'm trying to do a universal connection. so whenever i need to insert, update or delete.. i will call
this class...
I work with C# so I am not very good at VB. But I know that you will need to declare the variables as class members a little bit like this:
~~~~~~~~~~~~~~~~~~
Imports Microsoft.VisualBasic
Imports mysql.data.mysqlclient
Public Class Class2
Dim mysqlconnectionstring As String = "server = server; database=database; uid=uid; pwd=pwd;connect timeout=30;"
Dim myadoconnection As New MySqlConnection()
Sub DBStuff()
myadoconnection.ConnectionString = mysqlconnectionstring
myadoconnection.Open()
End Sub
End Class
~~~~~~~~~~~~~~~~~~~
By declaring the variables as class members this will fix the error you were having.
I think it is mostly related to scope. If the variables are declared as class members then they are sure to be initialised. But if they are declared in a sub then there is no way of making sure these variables are in the execution path and they may not
get initialised. I don't really know how to explain it much better than that, it is the way I have always done it.
I am glad I could help you with your problem, and also please mark this post as answer.
I'm a student doing my final year project and i came across an error saying "declaration expected" to the "A". I have declared
the variables like what i've found on a website but still couldnt remove the error.
Public Declare Function SendMessage Lib "user32" Alias "SendMessage" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Public Declare Function SendMessageStr Lib "user32" Alias "SendMessage" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As String, ByVal lParam As String) As Long
Dim A As Boolean
A = SendMessage(hWnd, wm_cap_driver_connect, 0, 0)
A = SendMessage(hWnd, WM_CAP_SET_SCALE, True, 0)
A = SendMessage(hWnd, WM_CAP_DLG_VIDEOCOMPRESSION, 0, 0)
A = SendMessageStr(hWnd, WM_CAP_FILE_SET_CAPTURE_FILE, "D:\Recorded.avi", 0)
A = SendMessage(hWnd, WM_CAP_SET_SEQUENCE_SETUP, 96, 0)
A = SendMessage(hWnd, WM_CAP_SEQUENCE, 0, 0)
yongweixiang...
0 Points
5 Posts
Declaration Expected
Feb 27, 2008 11:43 PM|LINK
Dim mysqlconnectionstring As String = "server = server; database=database; uid=uid; pwd=pwd;connect timeout=30;"
Dim myadoconnection As New MySqlConnection()
myadoconnection.connectionstring = mysqlconnectionstring
myadoconnection.open()
Hi, i have this above code in class.vb... i'm doing a website project. i would need to do a connection to database in order for me to insert data into the database.
but when i have "myadoconnection.connectionstring = mysqlconnectionstring", the word in bold gave me error... "Declaration Expected" but i already declared it on the second line.
i'm stuck. please help me... i really appreciate it very much... thank you :)
petermeadit
Member
653 Points
179 Posts
Re: Declaration Expected
Feb 28, 2008 01:15 AM|LINK
Make sure you have this Imports statement:
Imports
System.Data.SqlClientNow take the 'My' off the SqlConnection() so
Dim myadoconnection As New MySqlConnection()
should be
Dim
myadoconnection As New SqlConnection()yongweixiang...
0 Points
5 Posts
Re: Declaration Expected
Feb 28, 2008 01:31 AM|LINK
Hi thanks for the reply...
by the way... the database i'm using is MySQL, therefore i imports mysql.data.mysqlclient
that's why i'm declaration are with a 'My' infront.
so any idea to solve the problem for declaration expected problem when using mysql. Thanks alot :)
petermeadit
Member
653 Points
179 Posts
Re: Declaration Expected
Feb 28, 2008 01:52 AM|LINK
I have never used the MySql provider so I probably can't help you much there.
I run this code in VS 2005 with no problems so your problem might be with the MySql provider?
Imports System.Data.SqlClient Partial Class Default11 Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim mysqlconnectionstring As String = "server = server; database=database; uid=uid; pwd=pwd;connect timeout=30;" Dim myadoconnection As New SqlConnection() myadoconnection.ConnectionString = mysqlconnectionstring myadoconnection.open() End Sub End Classyongweixiang...
0 Points
5 Posts
Re: Declaration Expected
Feb 28, 2008 02:00 AM|LINK
Hi, oh.. you place the code in Page_Load, will there be any different if mine is in the class.vb?
yongweixiang...
0 Points
5 Posts
Re: Declaration Expected
Feb 28, 2008 02:03 AM|LINK
Hi.. realise one thing. as mention with the code that you put in, i change to mysqlclient. and is okie... so probably i can't do it in class.vb... because i'm trying to do a universal connection. so whenever i need to insert, update or delete.. i will call this class...
petermeadit
Member
653 Points
179 Posts
Re: Declaration Expected
Feb 28, 2008 03:32 AM|LINK
I work with C# so I am not very good at VB. But I know that you will need to declare the variables as class members a little bit like this:
~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~
By declaring the variables as class members this will fix the error you were having.
Hope This Helps you a Little
yongweixiang...
0 Points
5 Posts
Re: Declaration Expected
Feb 28, 2008 05:02 AM|LINK
Hi, it works with sub class... this is weird... why is it neccessary.... do you able to get an explanation?
By the way thank you :)
petermeadit
Member
653 Points
179 Posts
Re: Declaration Expected
Feb 28, 2008 10:45 AM|LINK
I think it is mostly related to scope. If the variables are declared as class members then they are sure to be initialised. But if they are declared in a sub then there is no way of making sure these variables are in the execution path and they may not get initialised. I don't really know how to explain it much better than that, it is the way I have always done it.
I am glad I could help you with your problem, and also please mark this post as answer.
Have a great day and happy programming!
KateLow
Member
2 Points
1 Post
Re: Declaration Expected
Jun 29, 2012 09:09 AM|LINK
Hi,
I'm a student doing my final year project and i came across an error saying "declaration expected" to the "A". I have declared the variables like what i've found on a website but still couldnt remove the error.
Public Declare Function SendMessage Lib "user32" Alias "SendMessage" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long Public Declare Function SendMessageStr Lib "user32" Alias "SendMessage" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As String, ByVal lParam As String) As Long Dim A As Boolean A = SendMessage(hWnd, wm_cap_driver_connect, 0, 0) A = SendMessage(hWnd, WM_CAP_SET_SCALE, True, 0) A = SendMessage(hWnd, WM_CAP_DLG_VIDEOCOMPRESSION, 0, 0) A = SendMessageStr(hWnd, WM_CAP_FILE_SET_CAPTURE_FILE, "D:\Recorded.avi", 0) A = SendMessage(hWnd, WM_CAP_SET_SEQUENCE_SETUP, 96, 0) A = SendMessage(hWnd, WM_CAP_SEQUENCE, 0, 0)Thanks a lot for your help(: