July 22, 2013
I would like to share a simple code which currently I am doing. This is a very basic application you may design for your website and require a database connection to Oracle databases.
First, lets go to the design of it. This is truely very useful for beginner like me especially you do not know where to start with. I am using Microsoft Visual Studio 2012 for Web to design my application website.
Second, talk about the Oracle connection string. I have quite sometime searching for correct oracle connection string that works (on my machine at least). You may copied it over, hopefully it will works on you too. Please change where necessary in the string follow your server configuration and setting.
First, lets go to the design of it. This is truely very useful for beginner like me especially you do not know where to start with. I am using Microsoft Visual Studio 2012 for Web to design my application website.
Second, talk about the Oracle connection string. I have quite sometime searching for correct oracle connection string that works (on my machine at least). You may copied it over, hopefully it will works on you too. Please change where necessary in the string follow your server configuration and setting.
Now, when you double click on Button from the project, it will bring you to the new coding page. This file is normally ended with *.vb filename. Here will be the location to paste the Oracle connection string as pasted above. Below is how the code will be looks alike:"Data Source=(DESCRIPTION=" _+ "(ADDRESS_LIST=" _+ "(LOAD_BALANCE=YES)" _+ "(FAILOVER=YES)" _+ "(ADDRESS=(PROTOCOL=tcp)(HOST=YOUR_HOST_NAME)(PORT=YOUR_PORT))" _+ "(ADDRESS=(PROTOCOL=tcp)(HOST=YOUR_HOST_NAME)(PORT=YOUR_PORT))" _+ ")" _+ "(CONNECT_DATA=" _+ "(SERVICE_NAME=YOUR_SERVICE_NAME)" _+ ")" _+ ");" _+ "User ID=YOUR_USER_ID;Password=YOUR_PASSWORD;"
Above code working just fine when I debug the project and click the button. This may help you to explore more on query to Oracle database for your project.Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click'Your Oracle connection SettingDim strConnString As String = "Data Source=(DESCRIPTION=" _+ "(ADDRESS_LIST=" _+ "(LOAD_BALANCE=YES)" _+ "(FAILOVER=YES)" _+ "(ADDRESS=(PROTOCOL=tcp)(HOST=YOUR_HOST_NAME)(PORT=YOUR_PORT))" _+ "(ADDRESS=(PROTOCOL=tcp)(HOST=YOUR_HOST_NAME)(PORT=YOUR_PORT))" _+ ")" _+ "(CONNECT_DATA=" _+ "(SERVICE_NAME=YOUR_SERVICE_NAME)" _+ ")" _+ ");" _+ "User ID=YOUR_USER_ID;Password=YOUR_PASSWORD;"'Your sql statement goes hereDim strQuery As String = "SELECT cus_name from tbl_cus where cus_ID = '" + TextBox1.Text + "'"Dim con As New OracleConnection(strConnString)Dim cmd As New OracleCommand()cmd.CommandType = CommandType.Textcmd.CommandText = strQuerycmd.Connection = conTrycon.Open()Dim sdr As OracleDataReader = cmd.ExecuteReader()While sdr.Read()'Here will be your output resultLabel1.Text = "Item"End WhileCatch ex As ExceptionThrow exFinallycon.Close()con.Dispose()End TryEnd Sub
No comments:
Post a Comment