VB.NET & System.Data.OracleClient - DataSet() - How to learn Connector/NET ADO.NET component System.Data.OracleClient namespace is the .NET Framework Data Provider for Oracle data source, Create a new DataSet and fill it using the DataAdapter from Oracle (Oracle Server Database)
ShotDev Focus:
- VB.NET & System.Data.OracleClient - DataSet()
Example
DataSet1.aspx
<%@ Import Namespace="System.Data"%> <%@ Import Namespace="System.Data.OracleClient"%> <%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) BindData() End Sub Sub BindData() '*** DataSet ***' Dim ds As DataSet ds = CreateDataSet() myRepeater.DataSource = ds.Tables(0).DefaultView myRepeater.DataBind() End Sub '*** DataSet ***' Function CreateDataSet() As DataSet Dim objConn As New System.Data.OracleClient.OracleConnection Dim objCmd As New System.Data.OracleClient.OracleCommand Dim dtAdapter As New System.Data.OracleClient.OracleDataAdapter Dim ds As New DataSet Dim strConnString,strSQL As String strConnString = "Data Source=TCDB;User Id=myuser;Password=mypassword;" strSQL = "SELECT * FROM customer" objConn.ConnectionString = strConnString With objCmd .Connection = objConn .CommandText = strSQL .CommandType = CommandType.Text End With dtAdapter.SelectCommand = objCmd dtAdapter.Fill(ds) dtAdapter = Nothing objConn.Close() objConn = Nothing Return ds '*** Return DataSet ***' End Function </script> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <form id="form1" runat="server"> <asp:Repeater id="myRepeater" runat="server"> <HeaderTemplate> <table border="1"> <tr> <th>CustomerID</th> <th>Name</th> <th>Email</th> <th>CountryCode</th> <th>Budget</th> <th>Used</th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td align="center"><%#Container.DataItem("CustomerID") %></td> <td><%#Container.DataItem("Name") %></td> <td><%#Container.DataItem("Email") %></td> <td align="center"><%#Container.DataItem("CountryCode") %></td> <td align="right"><%#Container.DataItem("Budget") %></td> <td align="right"><%#Container.DataItem("Used") %></td> </tr> </ItemTemplate> </asp:Repeater> </form> </body> </html>
Screenshot
.
.
.
Download this script.
.
.
.
VB.NET & System.Data.OracleClient - DataSet() - How to create a multiple table in DataSet .
ShotDev Focus:
- VB.NET & System.Data.OracleClient - DataSet()
Example
DataSet2.aspx
<%@ Import Namespace="System.Data"%> <%@ Import Namespace="System.Data.OracleClient"%> <%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) BindData() End Sub Sub BindData() '*** DataSet From DataSet ***' Dim ds As DataSet ds = CreateDataSet() Dim i As Integer Dim dg As DataGrid Dim lbl As Label For i = 0 To ds.Tables.Count - 1 dg = New DataGrid With dg .DataSource = ds.Tables(i).DefaultView .AutoGenerateColumns = True .DataBind() End With lbl = New Label lbl.Text = "<br><b>" & ds.Tables(i).ToString & "</b><br>" Me.lblText.Controls.Add(lbl) Me.lblText.Controls.Add(dg) dg = Nothing Next End Sub '*** DataSet ***' Function CreateDataSet() As DataSet Dim objConn As New System.Data.OracleClient.OracleConnection Dim objCmd As New System.Data.OracleClient.OracleCommand Dim dtAdapter As New System.Data.OracleClient.OracleDataAdapter Dim ds As New DataSet Dim i As Integer Dim strConnString,strSQL As String strConnString = "Data Source=TCDB;User Id=myuser;Password=mypassword;" Dim TablesName(2) As String TablesName(0) = "customer" TablesName(1) = "audit_log" TablesName(2) = "country" For i = 0 To TablesName.GetUpperBound(0) strSQL = "SELECT * FROM " & TablesName(i) & " " objConn.ConnectionString = strConnString With objCmd .Connection = objConn .CommandText = strSQL .CommandType = CommandType.Text End With dtAdapter.SelectCommand = objCmd dtAdapter.Fill(ds,TablesName(i)) Next dtAdapter = Nothing objConn.Close() objConn = Nothing Return ds '*** Return DataSet ***' End Function </script> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <form id="form1" runat="server"> <asp:Label id="lblText" runat="Server"></asp:Label> </form> </body> </html>
Screenshot
.
.
.
Download this script.
.
.
.
VB.NET & System.Data.OracleClient - DataSet() - How to use DataSet and adding new Row to DataSet.
ShotDev Focus:
- VB.NET & System.Data.OracleClient - DataSet()
Example
DataSet3.aspx
<%@ Import Namespace="System.Data"%> <%@ Import Namespace="System.Data.OracleClient"%> <%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) BindData() End Sub Sub BindData() '*** DataSet ***' Dim ds As DataSet ds = CreateDataSet() '*** Adding Rows to DataSet ***' Dim dr As DataRow dr = ds.Tables("customer").NewRow() dr.Item("CustomerID") = "C005" dr.Item("Name") = "Weerachai Nukitram" dr.Item("Email") = "webmaster@shotdev.com" dr.Item("CountryCode") = "TH" dr.Item("Budget") = "2000000" dr.Item("Used") = "100000" ds.Tables("customer").NewRow() ds.Tables("customer").Rows.Add(dr) '*** Adding Rows to DataSet ***' Me.myGridView.DataSource = ds.Tables(0).DefaultView Me.myGridView.DataBind() End Sub '*** DataSet ***' Function CreateDataSet() As DataSet Dim objConn As New System.Data.OracleClient.OracleConnection Dim objCmd As New System.Data.OracleClient.OracleCommand Dim dtAdapter As New System.Data.OracleClient.OracleDataAdapter Dim ds As New DataSet Dim strConnString,strSQL As String strConnString = "Data Source=TCDB;User Id=myuser;Password=mypassword;" strSQL = "SELECT * FROM customer " objConn.ConnectionString = strConnString With objCmd .Connection = objConn .CommandText = strSQL .CommandType = CommandType.Text End With dtAdapter.SelectCommand = objCmd dtAdapter.Fill(ds,"customer") dtAdapter = Nothing objConn.Close() objConn = Nothing Return ds '*** Return DataSet ***' End Function </script> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <form id="form1" runat="server"> <asp:GridView id="myGridView" runat="server"></asp:GridView> </form> </body> </html>
Screenshot
2outline…
…