problems with code can someone help??

  • Thread starter Thread starter Ron
  • Start date Start date
R

Ron

I am having a bit of problem with this code:

Dim cmd As New OleDb.OleDbCommand("INSERT INTO help (Name, Email,
telephone, description)VALUES('" & txtName.Text & "','" &
txtEmail.Text & "','" & txtTelephone.Text & "','" &
txtDescription.Text & "')", New OleDb.OleDbConnection(strconn))

at the end, strconn is underlined in blue and says not defined, I
dont know what to do with this, how do I define it?

Also I have 2 forms...one button shold hide the one form and show
another, here is the code I have and it is not working:

Form2.Show()
Me.Hide()

it does nothing, the new form does not show and me does not hide.

thanks for any help.
 
I am having a bit of problem with this code:

Dim cmd As New OleDb.OleDbCommand("INSERT INTO help (Name, Email,
telephone, description)VALUES('" & txtName.Text & "','" &
txtEmail.Text & "','" & txtTelephone.Text & "','" &
txtDescription.Text & "')", New OleDb.OleDbConnection(strconn))

at the end, strconn is underlined in blue and says not defined, I
dont know what to do with this, how do I define it?

Also I have 2 forms...one button shold hide the one form and show
another, here is the code I have and it is not working:

Form2.Show()
Me.Hide()

it does nothing, the new form does not show and me does not hide.

thanks for any help.
at the end, strconn is underlined in blue and says not defined, I
dont know what to do with this, how do I define it?

I guessing that strconn is supposed to be a string that equals your
OleDb connection string to your database. To get the appropriate
format see www.connectionstrings.com

Here's is how I would write your code:

Dim conn As New OleDbConnection("enter your connection string here")
Using (conn)
conn.Open()
Dim com As OleDbCommand = conn.CreateCommand()
Using (com)
com.CommandType = CommandType.Text
com.CommandText = String.Format("Insert Into help(Name, Email,
telephone, description) Values ('{0}', '{1}', '{2}', '{3}')",
txtName.Text, txtEmail.Text, txtTelephone.Text, txtDescription.Text)
com.ExecuteNonQuery()
End Using
End Using
Also I have 2 forms...one button shold hide the one form and show
another, here is the code I have and it is not working:

Try this:

Dim f As New Form2()
f.Show()
Me.Hide()

That should create a new instance (instantiate) of Form2 and show it.
Immediately afterwards it will hide the calling form. Is that what you
were looking for?

Thanks,

Seth Rowe
 
I guessing that strconn is supposed to be a string that equals your
OleDb connection string to your database. To get the appropriate
format seewww.connectionstrings.com

Here's is how I would write your code:

Dim conn As New OleDbConnection("enter your connection string here")
Using (conn)
conn.Open()
Dim com As OleDbCommand = conn.CreateCommand()
Using (com)
com.CommandType = CommandType.Text
com.CommandText = String.Format("Insert Into help(Name, Email,
telephone, description) Values ('{0}', '{1}', '{2}', '{3}')",
txtName.Text, txtEmail.Text, txtTelephone.Text, txtDescription.Text)
com.ExecuteNonQuery()
End Using
End Using


Try this:

Dim f As New Form2()
f.Show()
Me.Hide()

That should create a new instance (instantiate) of Form2 and show it.
Immediately afterwards it will hide the calling form. Is that what you
were looking for?

Thanks,

Seth Rowe

thanks, I tried, ther strconn went away but now when I open form2,
or go to it by pressing the button and go into a textbox by clicking
in a textbox I get an error LoaderLock detected
 
thanks, I tried, ther strconn went away but now when I open form2,
or go to it by pressing the button and go into a textbox by clicking
in a textbox I get an error LoaderLock detected

Wow - that was a scrambled sentence. First things first - the database
interaction is working and form2 is showing right?

Thanks,

Seth Rowe
 
Wow - that was a scrambled sentence. First things first - the database
interaction is working and form2 is showing right?

Thanks,

Seth Rowe

Wow yes I don't know what happened with that sentence. Anyway, yes
the database is read into a datagrid and displayed on form1 at
startup, on load.

here is my code for both forms.
this is for form1.vb, frmmain

Imports System.Data.OleDb
Public Class frmMain

Dim olecn As New _
OleDb.OleDbConnection("Provider=Microsoft.jet.oledb.4.0;" & _
"Data Source=helpdesk.mdb")



Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnExit.Click
Me.Close()

End Sub

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim olecmd As New OleDbCommand _
("Select * from help", olecn)

Dim oleda As New OleDbDataAdapter(olecmd)

Dim oleds As New DataSet
oleda.Fill(oleds)

dgvHelp.DataSource = oleds.Tables(0)
End Sub

Private Sub dgvHelp_CellContentClick(ByVal sender As
System.Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles
dgvHelp.CellContentClick

End Sub

Private Sub btnNewCall_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnNewCall.Click
Dim f As New Form2()
f.Show()
Me.Hide()
End Sub
End Class

this is for form2, form2
Imports System.Data.OleDb

Public Class Form2

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click


Dim conn As New OleDbConnection("enter your connection string
here")
Using (conn)
conn.Open()
Dim com As OleDbCommand = conn.CreateCommand()
Using (com)
com.CommandType = CommandType.Text
com.CommandText = String.Format("Insert Into
help(Name, Email, telephone, description) Values ('{0}', '{1}', '{2}',
'{3}')", txtName.Text, txtEmail.Text, txtTelephone.Text,
txtDescription.Text)
com.ExecuteNonQuery()
End Using
End Using
End sub
End Class
 
Back
Top