PebHmong Discussion Forum
Hobbies & Interests => Computer & Technology => Topic started by: Aglaea on February 28, 2011, 02:12:56 PM
-
I have a project for a database class using visual basic 2008 express and mysql workbench.
i need to connect the forms through persistors but i am not having any luck.
can someone help me?
an error msg i get when trying to run the program is:
"Type 'company' is not defined"
Imports MySql.Data.MySqlClient
Public Class companyPersistor
Dim M_con As New MySqlConnection
Dim oCommand As New MySqlCommand
Shared M_Persistor As companyPersistor
Private Sub New()
End Sub
Shared Function GetPersistor() As companyPersistor
If M_Persistor Is Nothing Then
M_Persistor = New companyPersistor
M_Persistor.connect()
End If
Return M_Persistor
End Function
Private Sub connect()
If M_con.State = ConnectionState.Closed Then
M_con.ConnectionString = "server= localhost ; user id=newuser; database='indproj'"
M_con.Open()
End If
End Sub
Private Sub disconnect()
M_con.Close()
End Sub
Public Sub InsertCompany(ByVal p_company As company)
connect()
Dim oCommand As New MySqlCommand
oCommand.Connection = M_con
oCommand.CommandText = "insert into company (CompanyName, street, city, zipcode,phonenumber) values('" & p_company.CompanyName & "', '" & p_company.city & "', '" & p_company.zipcode & "', '" & p_company.state & "', '" & p_company.phonenumber & "')"
oCommand.ExecuteNonQuery()
End Sub
End Class
-
Here is a printscreen of my database:
what i want to do is that when a user enters in information, the information is save directly into the tables.
my table is named 'company' for the database.
(http://i1132.photobucket.com/albums/m580/kayooz/Untitled-1.jpg)
-
I don't have VS installed at the moment, so I might not be able to help much.
just stressed out. any help would greatly be appreciated.
here's a free vb express 2008 you can download:
http://www.microsoft.com/express/Downloads/
here's a download of mysql workbench:
http://dev.mysql.com/downloads/workbench/
-
Where is "company" defined? Could you mean "companyPersist or" ?
this is where i am stumpped.. i could not find where I will need to define 'company' in..
when i changed company to companyPersist or..it still gaved me an error.. seriously..am stuck..
i used the classexample code and pretty much cut and paste and manipulated and i get that 'not defined' error so i really don't know where i would need to define it....
i double checked the class code example and it wasn't define anywhere as well. :-\
-
Public Class frmPurchaseOrder
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim r As New Random
Try
txtorderno.Text = r.Next(100000, 999999999)
Catch
End Try
'----------help!!!
Dim company As New company
Dim saveP As companyPersistor
Dim APurchasingOrder As PurchaseOrder
saveP = companyPersistor.GetPersistor
Company = New company
company.Phone = "2541"
company.CompanyName = grpCompInfo1.CompanyName 'purchaseorder.Text
company.Address = company.adress
saveP.insertCompany(company)
End Sub
Private Sub frmPurchaseOrder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
so with this added: i get 3 errors of all the same error msg about 'company' not being defined.
*help!!
-
Hmm.. that's odd. Well for sure it needs to be defined, because you're setting the input p_company As company, which you're using as a structure or object or class.
p_company.Comp anyName
p_company.city
p_company.zipc ode
p_company.stat e
p_company.phon enumber
The place to look would be where p_company is originally declared.
I would imagine the company structure would look something like this:
Structure company
Private CompanyName As String
Private city As String
Private zipcode As Integer
Private state As String
Private phonenumber As String
End Structure
And then p_company would be an instance of company:
Dim p_company As New company
Then after creating that instance of company, you would populate p_company with data before using it in your sql query.
Again, I'm not too sure but just look for those clues. Just look for where p_company is originally declared/defined,
and you should see which class/object/structure it is an instance of, and that should be used in your:
Public Sub InsertCompany(ByVal p_company As <original class/object/structure>)
Sorry, there's a lot of information i'm missing so again, just throwing out ideas.
i use this idea for my previous reply...still no luck.
-
Where is your "Public Class company" code? Or "Public Class p_company" code? Show us that code. In fact, show us all your code, the error log would help too.
-
Going off of OutsidetTheBox, try this; instead of private, which can't be accessed; try public in the struct.
Imports MySql.Data.MySqlClient
Public Class companyPersistor
Dim M_con As New MySqlConnection
Dim oCommand As New MySqlCommand
Shared M_Persistor As companyPersistor
Private Sub New()
End Sub
Shared Function GetPersistor() As companyPersistor
If M_Persistor Is Nothing Then
M_Persistor = New companyPersistor
M_Persistor.connect()
End If
Return M_Persistor
End Function
Private Sub connect()
If M_con.State = ConnectionState.Closed Then
M_con.ConnectionString = "server= localhost ; user id=newuser; database='indproj'"
M_con.Open()
End If
End Sub
Private Sub disconnect()
M_con.Close()
End Sub
Public Sub InsertCompany(ByVal p_company As company)
connect()
Dim oCommand As New MySqlCommand
oCommand.Connection = M_con
oCommand.CommandText = "insert into company (CompanyName, street, city, zipcode,phonenumber) values('" & p_company.CompanyName & "', '" & p_company.city & "', '" & p_company.zipcode & "', '" & p_company.state & "', '" & p_company.phonenumber & "')"
oCommand.ExecuteNonQuery()
End Sub
Structure company
Public CompanyName As String
Public city As String
Public zipcode As Integer
Public state As String
Public phonenumber As String
End Structure
End Class
-
OutsideTheBox thank you so very much for helping me out O0 :-*
intel and jetter thanks for taking the initiative to help me out too.
(case closed--problem sloved)
-
You need to work on understanding OBJECT ORIENTED PROGRAMMING. :) .
i hardly understood anything in the class..
the class is only 2 hours long and only once a week for 7 weeks... 7th week this week and i've learn nothing.. until OUTsidetheBox took time to explain to me.
it's a sql database class.. who knew we had to use vb programming until last week of class. but i'll take your advice and find me a copy of the book.
-
You in trouble then. OOP and OOA/D is the foundation of modern programming languages. Objects are getting more complex. :)
Besta hit the textbook HARD. You might fail bro sista. That shoulda been a 30 second debug moment.
tell me about it! ???
where's a good place to start understanding ooa/d?
-
actually it's not in class. It's on the side with your group of nerdy classmates; group studies. Like you asking outsidethebox; he's able to connect with you better and explain it differently then a book would. Lecturer's are worthless, you only attend lecture to know what the exam will cover.
-
In class?
no not in class --self study stuffs.
-
actually it's not in class. It's on the side with your group of nerdy classmates; group studies. Like you asking outsidethebox; he's able to connect with you better and explain it differently then a book would. Lecturer's are worthless, you only attend lecture to know what the exam will cover.
yes, i think he (ouside-) does a very good job explaining..
i noticed there's a few very talented IT gurus in here.. you one of them too..
i never went to school for computer science but i do somewhat have some knowledge lol and decided to get educated the right way but seems like it's not working out for me...at least for programming classes..
we should have like a hmong networking group where we all can connect/teach and learn from one another...
-
nice once you get a little better and more comfortable in logics, you can learn these languages (php, c#, javascript via jquery) and I can send you some of my programming contracts. I will be paying you via paypal once the clients pays me.