Mono Support Access Database 

Viewed 28455 time(s), 4 post(s), 7/27/2014 1:05:25 AM - by Samtg
7/27/2014 1:05:25 AM
440 Reputation 38 Total posts

Hi,
     I have been trying to create a page that accesses some type of database (specifically a form-like page), to insert data into the database (mysql), and keep coming up with errors.  Is there a particular way in MonoX to access a database, or what does one need to do to do so?

Thanks.

1
7/27/2014 7:49:01 AM
15993 Reputation 2214 Total posts

Hi,

  Can you please provide us with error you get and also it would be great to see the code used to access the MySql db.

Regards

2
7/28/2014 5:53:37 PM
440 Reputation 38 Total posts

Yeah, actually I got it working somehow, except when I check the database, nothing is there.

Here is the code I got:


<%@ Page
    Language="C#"
    MasterPageFile="/MonoX/MasterPages/DefaultSmallHeader.master"
    AutoEventWireup="true"     
    Inherits="MonoSoftware.MonoX.BasePage"
    CodeBehind="FamGenSiteQ_.aspx.cs"
    Theme="Default"
    Title="" %>

<%@ MasterType TypeName="MonoSoftware.MonoX.BaseMasterPage" %>   
<%@ Register TagPrefix="MonoX" TagName="Editor" Src="/MonoX/ModuleGallery/MonoXHtmlEditor.ascx" %>
<%@ Register Assembly="MonoX" Namespace="MonoSoftware.MonoX" TagPrefix="portal" %>

<script runat="server">
 private void On_Click(Object source, EventArgs e) {
    try {
        SqlDataSource1.Insert();
    }
    catch (Exception except) {
        // Handle the Exception.
    }
 }
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="cp" runat="server">
    <div class="row-fluid">
        <div class="span12">
            <portal:PortalWebPartZone HeaderText="Left part zone" ID="leftWebPartZone" runat="server" Width="100%" ChromeTemplateFile="Standard.htm">
                <ZoneTemplate>
                    <MonoX:Editor runat="server" ID="editor1" />       
                 <asp:Panel runat="server" ID="pnlDescription">
                     <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          ConnectionString="<%$ ConnectionStrings:EmailandFamilyWebsiteDatabase%>"
          SelectCommand="SELECT Website, Email FROM Websites"
          InsertCommand="INSERT INTO Websites (Website, Email) VALUES (@Website, @Email)"><!-- SET Website=@Website WHERE Email =@Email">-->
          <InsertParameters>
              <asp:FormParameter Name="TextBox1" formfield="Text"/>
              <asp:FormParameter Name="TextBox2" formfield="Text"/>
          </InsertParameters>
      </asp:SqlDataSource>

      
<p>"Enter website for the selected user."</p?
AssociatedControlID="TextBox1" /> <br />
<asp:TextBox id="TextBox1" runat="server" /> <br />
<asp:TextBox id="TextBox2" runat="server" /> <br />
<asp:Button id="Submit" runat="server" Text="Submit" OnClick="On_Click" />
                       
                </asp:Panel>
                </ZoneTemplate>
            </portal:PortalWebPartZone>
      
        </div>
    </div>
</asp:Content>

Thanks.

3
8/4/2014 10:00:06 AM
15993 Reputation 2214 Total posts

Are you actually sure that SqlDataSource is inserting records into database ? Did you check the following line

catch (Exception except) {
    // Handle the Exception.
}
Do you get an exception here ?

Regards

4
This is a demo site for MonoX. Please visit Mono Software for more info.