MonoX support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

Access Database  (Mono Support )

Viewed 27334 time(s), 4 post(s) 7/27/2014 1:05:25 AMby Samtg
Samtg

Samtg

7/27/2014 1:05:25 AM
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.
This content has not been rated yet. 
440 Reputation 38 Total posts
khorvat

khorvat

7/27/2014 7:49:01 AM
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
This content has not been rated yet. 
15993 Reputation 2214 Total posts
Samtg

Samtg

7/28/2014 5:53:37 PM
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.
This content has not been rated yet. 
440 Reputation 38 Total posts
khorvat

khorvat

8/4/2014 10:00:06 AM
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
This content has not been rated yet. 
15993 Reputation 2214 Total posts