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