Computing.Net > Forums > Programming > need help with VB program

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

need help with VB program

Reply to Message Icon

Name: constantin
Date: February 8, 2008 at 08:58:23 Pacific
OS: windows
CPU/Ram: intel
Product: IBM
Comment:

Here is a sample of the whole process; we can use three forms to guide through:

On Form 1, 1)You input client options (ODBC which is Radiobutton1 or Native which is Radiobutton2), 2)data source which is TextBox1 such as dprod, user name which is TextBox2, password which is TextBox3(should be encrypted on the screen)and also a next button on same form which is Button1

After next button is clicked, you will need to check if each box is empty or not; If not, you will need to prompt error message for user.

If all the nessary fields filled, you will need to try to connect to database; if the connection fails, prompt for database connection error and detail database feedback error message.

If database connects, close form 1 and open form 2, On form2 , you have owner, table/view selection criteria;

select all the owners out from the database meta table to populate the owner list for the second form by using the opened connection from form 1.

a user picks a lists of owners and possiblely to extend to owners and tables/views,

if owners/table/view selection is null when next is clicked, prompt error message;

if not , you move to the third forms (close the second form) to show ready to Proceed or Cancel ; if Cancel is clicked, exit your program; or

when Proceed is clicked,

constructure SELECTs to read from database metadata,
insert into META* tables

when all the Selects finsihed, prompt the end of process.

thanks,this is my code so far for form1,2 when I ran the program I got you select ODBC and then error even though I put the right username and password:


Imports System
Imports System.Data ' VB.NET
Imports Oracle.DataAccess.Client ' ODP.NET Oracle data provider


Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


' Create the connection object
Dim con As OracleConnection = New OracleConnection()

' Specify the connect string
' NOTE: Modify User Id, Password, Data Source as per your database set up
con.ConnectionString = "User Id=rab;Password=pass;Data Source=dprod"

Try
' Open database connection through ODP.NET
con.Open()
Console.WriteLine("Connection to Oracle database established successfully !")
Console.WriteLine(" ")

Catch ex As Exception

Console.WriteLine(ex.Message)
End Try

Dim cmdQuery As String = "SELECT table_name FROM user_tables WHERE table_name like 'META_%"

' Create the OracleCommand object
Dim cmd As OracleCommand = New OracleCommand(cmdQuery)
cmd.Connection = con
cmd.CommandType = CommandType.Text

Try
' Fetch data into an OracleDataReader object and display the data on the console. Then, close the connection object
Dim reader As OracleDataReader = cmd.ExecuteReader()
While (reader.Read())

' Output PACKAGEGUID and PKG_COMMENT
Console.WriteLine("PACKAGEGUID: " & _
reader.GetDecimal(0) & _
" , " & _
"PKG_COMMENT: " & _
reader.GetString(1))

End While
Catch ex As Exception

Console.WriteLine(ex.Message)

Finally

' Dispose OracleCommand object
cmd.Dispose()

' Close and Dispose OracleConnection object
con.Close()
con.Dispose()

End Try
End Sub

Private Sub BindingNavigatorPositionItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged

End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged

End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

If RadioButton2.Checked = True Then
MsgBox("You chose Native/Direct Connection")
Else
MsgBox("You chose ODBC")
End If

If ComboBox1.Text = "" Then
MessageBox.Show("ComboBox1 is empty")
End If

If TextBox2.Text = "" Then
MessageBox.Show("username is empty")
End If

If TextBox1.Text <> "rab" Then
MsgBox("error")
Else

If TextBox2.Text <> "pass" Then
MsgBox("password is not right")
Else
Me.Hide()
Form2.Show()
End If
End If

' 1)Create the connection object
Dim con As OracleConnection = New OracleConnection()


'2) Open database connection through ODP.NET
Try

' Open the connection
con.Open()
Console.WriteLine("Connection to Oracle database established successfully !")
Console.WriteLine(" ")

Catch ex As Exception

Console.WriteLine(ex.Message)
End Try

'3)Create command object to perform a query against the database
Dim cmdQuery As String = "SELECT PACKAGEGUID, PKG_COMMENT FROM META_AUDIT"
' Create the OracleCommand object
Dim cmd As OracleCommand = New OracleCommand(cmdQuery)
cmd.Connection = con
cmd.CommandType = CommandType.Text
'4)Fetch data into an OracleDataReader object and display the data on the console
' Then, close the connection object
Try

' Execute command, create OracleDataReader object
Dim reader As OracleDataReader = cmd.ExecuteReader()
While (reader.Read())

' Output Employee Name and Number
Console.WriteLine("PACKAGEGUID : " & _
reader.GetDecimal(0) & _
" , " & _
"PKG_COMMENT : " & _
reader.GetString(1))

End While
Catch ex As Exception

Console.WriteLine(ex.Message)

Finally

' Dispose OracleCommand object
cmd.Dispose()

' Close and Dispose OracleConnection object
con.Close()
con.Dispose()

End Try

' Specify the connect string
' NOTE: Modify User Id, Password, Data Source as per your database set up
'con.ConnectionString = "User Id=rab;Password=pass;Data Source=dprod;"


Dim myForm As New Form2
myForm.Show()
'Me.Hide()
'Form2.Show()

End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged

End Sub

Private Sub TextBox3_TextChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged

End Sub

Private Sub ComboBox1_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

End Sub
End Class
,,,,,,,,,,,,,,,,,,,,this is Form2 below
Imports System.Data.OracleClient

Public Class Form2

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create the connection object

Dim con As OracleConnection = New OracleConnection()
con.ConnectionString = "Data Source=dprod;User ID= rab; Unicode=True; Password=pass"

End Sub
Private Sub Buton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim connectstr As String
connectstr = "Data Source=" & TextBox1.Text & ";" & "User ID=" & TextBox1.Text & "Unicode=True; Password=" & TextBox3.Text

Dim myForm As New Form1
myForm.Show()
End Sub

Private Sub Buton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim myForm As New Form1
myForm.Show()
'Me.Hide()
'Form1.Show()
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

End Sub

Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged

End Sub
End Class




Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: February 8, 2008 at 09:51:18 Pacific
Reply:

So whats the problem?

Stuart


0

Response Number 2
Name: constantin
Date: February 9, 2008 at 18:13:10 Pacific
Reply:

Hi Stuart there are few problems:1)when I login I put the wrong username and ran the prog.it willn't tell me username isn't right,also when I put wrong Datasource like dpeep it tells me Datasource empty,it should say wrong Datasource.Even If all the nessary fields filled, I can't connect to database(isn't giving me connection fails, prompt for database connection error and detail database feedback error message).I want If database connects, close form 1 and open form 2(it opens Form2 even if some information is wrong).There are some more problems but I hope u could help me with these first,thanks alot this is updated version of the code:


Imports System
Imports System.Data ' VB.NET
Imports Oracle.DataAccess.Client ' ODP.NET Oracle data provider


Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


' Create the connection object
Dim con As OracleConnection = New OracleConnection()

' Specify the connect string
' NOTE: Modify User Id, password, Data Source as per your database set up
con.ConnectionString = "User Id=smughrabi;password=Sul9966;Data Source=dprod"

Try
' Open database connection through ODP.NET
con.Open()
Console.WriteLine("Connection to Oracle database established successfully !")
Console.WriteLine(" ")

Catch ex As Exception

Console.WriteLine(ex.Message)
End Try

Dim cmdQuery As String = "SELECT table_name FROM user_tables WHERE table_name like 'META_%"

' Create the OracleCommand object
Dim cmd As OracleCommand = New OracleCommand(cmdQuery)
cmd.Connection = con
cmd.CommandType = CommandType.Text

Try
' Fetch data into an OracleDataReader object and display the data on the console. Then, close the connection object
Dim reader As OracleDataReader = cmd.ExecuteReader()
While (reader.Read())

' Output PACKAGEGUID and PKG_COMMENT
Console.WriteLine("PACKAGEGUID: " & _
reader.GetDecimal(0) & _
" , " & _
"PKG_COMMENT: " & _
reader.GetString(1))

End While
Catch ex As Exception

Console.WriteLine(ex.Message)

Finally

' Dispose OracleCommand object
cmd.Dispose()

' Close and Dispose OracleConnection object
con.Close()
con.Dispose()

End Try
End Sub

Private Sub BindingNavigatorPositionItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged

End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged

End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


If RadioButton2.Checked = True Then
MsgBox("You chose Native/Direct Connection")
Else
MsgBox("You chose ODBC")
End If

If ComboBox1.Text = "" Then
MessageBox.Show("ComboBox1 is empty")
End If

If TextBox2.Text = "" Then
MessageBox.Show("username is empty")
End If

If TextBox1.Text <> "dprod" Then
MsgBox("Datasource is empty")
Else

If TextBox2.Text <> "smughrabi" Then
MsgBox("username is not right")
Else
Me.Hide()
Form2.Show()
End If
End If

' 1)Create the connection object
Dim con As OracleConnection = New OracleConnection()


'2) Open database connection through ODP.NET
Try

' Open the connection
con.Open()
Console.WriteLine("Connection to Oracle database established successfully !")
Console.WriteLine(" ")

Catch ex As Exception

Console.WriteLine(ex.Message)
End Try

'3)Create command object to perform a query against the database
Dim cmdQuery As String = "SELECT PACKAGEGUID, PKG_COMMENT FROM META_AUDIT"
' Create the OracleCommand object
Dim cmd As OracleCommand = New OracleCommand(cmdQuery)
cmd.Connection = con
cmd.CommandType = CommandType.Text
'4)Fetch data into an OracleDataReader object and display the data on the console
' Then, close the connection object
Try

' Execute command, create OracleDataReader object
Dim reader As OracleDataReader = cmd.ExecuteReader()
While (reader.Read())

' Output Employee Name and Number
Console.WriteLine("PACKAGEGUID : " & _
reader.GetDecimal(0) & _
" , " & _
"PKG_COMMENT : " & _
reader.GetString(1))

End While
Catch ex As Exception

Console.WriteLine(ex.Message)

Finally

' Dispose OracleCommand object
cmd.Dispose()

' Close and Dispose OracleConnection object
con.Close()
con.Dispose()

End Try

' Specify the connect string
' NOTE: Modify User Id, password, Data Source as per your database set up
'con.ConnectionString = "User Id=smughrabi;password=password;Data Source=dprod;"


Dim myForm As New Form2
myForm.Show()
'Me.Hide()
'Form2.Show()

End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged

End Sub

Private Sub TextBox3_TextChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged

End Sub

Private Sub ComboBox1_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

End Sub
End Class
,,,,,,,,,,,,,,,,,,,this is Form 2 below:

Imports System.Data.OracleClient

Public Class Form2

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim cn As New OracleConnection
cn.ConnectionString = "Data Source=dprod;User ID=smughrabi; Unicode=True; Password=Sul9966"

End Sub
Private Sub Buton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim connectstr As String
connectstr = "Data Source=" & TextBox1.Text & ";" & "User ID=" & TextBox1.Text & "Unicode=True; Password=" & TextBox3.Text

Dim myForm As New Form1
myForm.Show()
End Sub

Private Sub Buton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim myForm As New Form1
myForm.Show()
'Me.Hide()
'Form1.Show()
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

End Sub

Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged

End Sub
End Class


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


concatenate variable to s... Using a proxy through a w...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: need help with VB program

Need help with C++ program www.computing.net/answers/programming/need-help-with-c-program/5152.html

Need help with C++ program www.computing.net/answers/programming/need-help-with-c-program/19441.html

Need help with C programming www.computing.net/answers/programming/need-help-with-c-programming/6970.html