Current location: Hot Scripts Forums » Programming Languages » ASP.NET » [SOLVED] how can open database in asp.net


[SOLVED] how can open database in asp.net

Reply
  #1 (permalink)  
Old 06-25-08, 05:55 AM
jha jha is offline
Newbie Coder
 
Join Date: Jun 2008
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] how can open database in asp.net

how can open database and display records in asp.net
Reply With Quote
  #2 (permalink)  
Old 06-25-08, 05:58 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Reply With Quote
  #3 (permalink)  
Old 06-25-08, 08:51 AM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
What's your database? If MS Access, the sample Nico provided works. For SQL Server you have to use SQLClient.


Pete
__________________
Reply With Quote
  #4 (permalink)  
Old 06-26-08, 03:52 AM
jha jha is offline
Newbie Coder
 
Join Date: Jun 2008
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
No i wants to work with oracle database, i am using code below thats gives error
ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed
ERROR [01000] [Microsoft][ODBC Driver Manager] The driver doesn't support the version of ODBC behavior that the application requested (see SQLSetEnvAttr).
ERROR [01S00] [Microsoft][ODBC driver for Oracle]Invalid connection string attribute

Code:
<script runat="server">

    Sub submit(sender As Object, e As EventArgs)
    dim dbconn,sql,dbcomm,dbread
    dbconn=New odbcConnection("dsn=Oracle;UserId=starter;Password=starter; " )
    dbconn.Open()
    sql="SELECT * FROM students"
    dbcomm=New odbcCommand(sql,dbconn)
    dbread=dbcomm.ExecuteReader()
    customers.DataSource=dbread
    customers.DataBind()
    dbread.Close()
    dbconn.Close()
    End Sub

</script>
Reply With Quote
  #5 (permalink)  
Old 06-26-08, 12:13 PM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
Your connection string should be something like this (change "ServerName" with your server name):

Code:
Driver={Microsoft ODBC for Oracle};Server=ServerName;Uid=starter;Pwd=starter;
This is assuming that you have done the following first:

1. Install Oracle client
2. Configure TNS Names to connect to Oracle database through oracle client
3. Go to start> settings> control panel> administrator tools> ODBC connections - add a new ODBC connection using oracle driver
4. Use the connection string above.


What version of Oracle are you using?


Pete
__________________

Last edited by digioz; 06-26-08 at 12:19 PM.
Reply With Quote
  #6 (permalink)  
Old 06-26-08, 11:48 PM
jha jha is offline
Newbie Coder
 
Join Date: Jun 2008
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
I am using oracle 8
this code is now open database without error
Code:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@ import Namespace="System.Data.ODbc" %>
<%@ Import Namespace=" System.Data"%>
<script runat="server">
sub Page_Load(sender as Object, e as EventArgs)
     Dim strConnectionString As String
        strConnectionString = "Dsn=oracle;uid=starter;pwd=starter"
        Dim pConn As New OdbcConnection(strConnectionString)
        Dim pSELECTQUERY As String = "SELECT  *from test"
        Dim adapter As New OdbcDataAdapter(pSELECTQUERY, pConn)
        Dim DS As DataSet = New DataSet()
        adapter.Fill(DS)
		pConn.Close()
        adapter.Dispose()
    End Sub
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body>
    <form runat="server">

    </form>
</body>
</html>
but how can display the data store in adapter please help me out
Reply With Quote
  #7 (permalink)  
Old 06-27-08, 04:06 AM
jha jha is offline
Newbie Coder
 
Join Date: Jun 2008
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for your kind supports problems are now solved my full code is

Code:
<%@ Page Language="VB" %>
<%@ import Namespace="System.Data.ODbc" %>
<%@ Import Namespace=" System.Data"%>
<script runat="server">
sub Page_Load(sender as Object, e as EventArgs)
     Dim strConnectionString As String
        strConnectionString = "Dsn=oracle;uid=starter;pwd=starter"
        Dim pConn As New OdbcConnection(strConnectionString)
        Dim pSELECTQUERY As String = "SELECT  *from students"
        Dim adapter As New OdbcDataAdapter(pSELECTQUERY, pConn)
        Dim DS As DataSet = New DataSet()
        adapter.Fill(DS)
         Repeater1.DataSource = ds
        pConn.Close()
        adapter.Dispose()
        Repeater1.DataBind()
    End Sub
</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <asp:Repeater id="repeater1" runat="server">
            <HeaderTemplate>
                <table border="1" width="60%">
                    <tr bgcolor="#CCFF00">
                        <th>
                            ID</th>
                        <th>
                            Major</th>
                        <th>
                            First Name</th>
                        <th>
                            Last Name</th>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr bgcolor="#CCFFCC">
                    <th>
                        <%#Container.DataItem("id")%></th>
                    <th>
                        <%#Container.DataItem("major")%></th>
                    <th>
                        <%#Container.DataItem("first_name")%> 
                    </th>
                    <th>
                        <%#Container.DataItem("last_name")%> 
                    </th>
                </tr>
            </ItemTemplate>
            <AlternatingItemTemplate>
                <tr bgcolor="#CCFFFF">
                    <th>
                        <%#Container.DataItem("id")%></th>
                    <th>
                        <%#Container.DataItem("major")%></th>
                    <th>
                        <%#Container.DataItem("first_name")%> 
                    </th>
                    <th>
                        <%#Container.DataItem("last_name")%> 
                    </th>
                </tr>
            </AlternatingItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>
    </form>
</body>
</html>
i try to know whats parts of code should be write in .vb part and .aspx part
thanks
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
JS script not working properly on IE but working on Firefox!!! sujata_ghosh JavaScript 4 05-21-07 05:46 AM


All times are GMT -5. The time now is 02:39 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.