From: Andrew G. <ag...@jc...> - 2003-06-20 13:33:27
|
http://info.borland.com/devsupport/interbase/opensource/ <-- where you can get interbase open source http://sourceforge.net/project/showfiles.php?group_id=9028 <--- see firebird-net-provider I'm using Webmatrix to code my asp.net webforms with VB codebehind. See http://www.asp.net/webmatrix/default.aspx?tabIndex=4&tabId=46 Hey I like as much free stuff as I can get my hands on :) Here's some examples in VB one for a reader, a dataadapter, and a ExecuteNonQuery. I save the result to an xml file that I can use later instead of pounding the database with more queries. Note on the ExecuteNonQuery you have to have a Commit to get it to work unlike SQL Client or OleDb Client. <%@ Page Language="VB" Debug="true" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="FirebirdSql.Data.Firebird" %> <script runat="server"> Dim public shared myConnectionString As String Dim public shared myConnection As FbConnection Dim public shared myTxn As FbTransaction Dim public shared selectCmd As String Dim public shared mycommand As FbCommand Dim public shared myReader As FbDataReader Dim shared myXMLfile As String = "data.xml" Sub Connect() myConnectionString = "Database=C:\\interbase\\xxx\\xxx.GDB;User=xxx;Password=xxx;Dialect=3;Server =localhost;Pooling=False" myConnection = new FbConnection(myConnectionString) End Sub Sub Page_Load(Sender As Object, E As EventArgs) If Not (IsPostBack) 'Start postback Connect() myConnection.Open() selectCmd ="SELECT * FROM TBLSYSTEMS" myTxn = myConnection.BeginTransaction() myCommand = new FbCommand(selectCmd,myConnection,myTxn) myReader = myCommand.ExecuteReader() selectsystem.DataSource = myReader selectsystem.DataBind() myReader.close() myTxn.Dispose() myCommand.Dispose() myConnection.Close() End If 'End postback End Sub Sub BindGrid() Dim dataAdapter As FbDataAdapter Dim DS As New DataSet() Connect() myConnection.Open() dataAdapter = new FbDataAdapter() myTxn = myConnection.BeginTransaction() selectCmd = "SELECT * FROM QRYDB(@sdate,@edate,@alias) " myCommand = new FbCommand(selectCmd,myConnection,MyTxn) myCommand.parameters.add("@sdate",fbtype.date) myCommand.parameters("@sdate").value = DateAdd("h",-1,DateTime.Now) myCommand.parameters.add("@edate",fbtype.date) myCommand.parameters("@edate").value = DateAdd("h",1,DateTime.Now) myCommand.parameters.add("@alias",fbtype.VARCHAR,20) myCommand.parameters("@alias").value = strCPU Try dataAdapter.SelectCommand = myCommand dataAdapter.Fill(DS, "TempInfo") 'filldataset mydatagrid.DataSource = DS.Tables("TempInfo") mydatagrid.DataBind() dataAdapter.Dispose() myTxn.Dispose() myCommand.Dispose() myConnection.Close() Message2.Style("color") = "green" Message2.InnerHtml = "Matching Records = " & myDataGrid.Items.Count Catch Exp As FbException Message.Style("color") = "red" Message.InnerHtml = "ERROR:" & Exp.Message & "<br>" & selectcmd myTxn.Dispose() myCommand.Dispose() myConnection.Close() Exit Sub End Try DS.WriteXml(Server.MapPath(myXMLfile),XmlWriteMode.WriteSchema) End Sub Sub BindXML() Dim myDataSet as New DataSet() Dim fsReadXml As New System.IO.FileStream(Server.MapPath(myXMLfile), System.IO.FileMode.Open) Dim myView As New DataView() Try myDataSet.ReadXml(fsReadXml) myView = myDataSet.Tables(0).DefaultView mydatagrid.DataSource = myView mydatagrid.DataBind() Message2.Style("color") = "green" Message2.InnerHtml = "Matching Records = " & myDataGrid.Items.Count Catch ex As Exception Message.Style("color") = "red" Message.InnerHtml = ex.message.ToString() Finally fsReadXml.Close() End Try End Sub Sub GetNew(Sender As Object, E As EventArgs) BindGrid() End Sub Sub UseSaved(Sender As Object, E As EventArgs) BindXML() End Sub Sub MyDataGrid_Add(Sender As Object, E As DataGridCommandEventArgs) Connect() myConnection.Open() Dim InsertCmd As String Insertcmd = "INSERT INTO INFOAR(MSGNO, SEVERITY, MSG, KEYWORD) values(@msgno,@sev,@msg,'NONE')" myTxn = myConnection.BeginTransaction() MyCommand = New FbCommand(InsertCmd, MyConnection, myTxn) MyCommand.Parameters.Add("@msgno", FbType.Integer) MyCommand.Parameters("@msgno").Value = E.Item.Cells(6).Text MyCommand.Parameters.Add("@sev", FbType.VarChar, 18) MyCommand.Parameters("@sev").Value = E.Item.Cells(7).Text MyCommand.Parameters.Add("@msg", FbType.VarChar, 250) MyCommand.Parameters("@msg").Value = E.Item.Cells(8).Text Try MyCommand.ExecuteNonQuery() myTxn.Commit() myTxn.Dispose() myCommand.Dispose() Message.Style("color") = "Green" Message.InnerHtml = "<b>Record has been Added.</b><br>" Message2.Style("color") = "green" Message2.InnerHtml = "Matching Records = " & myDataGrid.Items.Count myConnection.Close() Catch Exp As FbException myTxn.Rollback() myTxn.Dispose() myCommand.Dispose() Message.Style("color") = "red" Message.InnerHtml = Exp.Message myConnection.Close() End Try End Sub Hope this is of help. Regards, Andrew Goodall. |