Jumat, 29 Juni 2012

Controler Utama membuat Module di C#

 Code Untuk Controler Utama di dalam membuat solution Module c#
 add newitem  ambil class.cs dan rename terserah anda di classnya dan masukan code di bawah ini:



using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace FormRegisterSolution
{
    public class Bases : System.Data.Linq.DataContext
    {
        public FormRegisterSolution.Entitas.RelationDataContext datacontext;
        public Bases()
            : base(System.Configuration.ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString)
        {
            datacontext = new FormRegisterSolution.Entitas.RelationDataContext(this.Connection.ConnectionString);
        }
    }
}



Controler Untuk masing masing table yang di diambil dari database

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FormRegisterSolution.Controler
{
    public class Rsscontroler : Bases
    {
        public List<FormRegisterSolution.Entitas.RSS> RSSlist
        {

            get
            {
                return datacontext.RSSes.ToList<FormRegisterSolution.Entitas.RSS>();
            }
        }
        public void addbskaryawan(FormRegisterSolution.Entitas.RSS obj)
        {
            datacontext.RSSes.InsertOnSubmit(obj);
            datacontext.SubmitChanges();
        }
        public void updaterss(int objguid, string objlocationstore, string objcategory, string objstory, string objdescription, string objlink, string objimage, string objtitle, DateTime objpubdate)
        {
            var verified = (from v in datacontext.RSSes where v.guid == objguid select v).Single();
           
            //verified.discount = objdiscount;
            verified.locationstore = objlocationstore;
     
            verified.category = objcategory;
           
            verified.story = objstory;
            verified.description = objdescription;
            verified.link = objlink;
            verified.imagepath = objimage;
            verified.title = objtitle;
            verified.pubdate = objpubdate;

            datacontext.SubmitChanges();
        }
    }
}

Kamis, 21 Juni 2012

Melakukan Bind data dengan menggunakan Data yang ada Di Database

Melakukan Bind data dengan menggunakan Data yang ada Di Database

Ada contoh melakukan bind data di bawah ini dimana sebelumnya melakukan penggambilan data dengan menggunakan SQLDatasource


 <tr>
            <td style="height: 1px;" valign="middle">
                Hubungan dengan ahli waris
            </td>
            <td style="height: 1px;" valign="middle">
                :
            </td>
            <td style="height: 1px;" valign="middle">
                <asp:DropDownList ID="txthubwaris" runat="server" Width="294px"

DataSourceID="DSwaris" DataTextField="Desc" DataValueField="CodeRef"  />
                <asp:RequiredFieldValidator Display="None"

ID="RequiredFieldValidator19" runat="server"
                    ControlToValidate="txthubwaris" ErrorMessage="Mohon diisi

hubungan dengan ahli waris"
                    ValidationGroup="updateProfile" SetFocusOnError="true"

/>&nbsp;
                    <asp:SqlDataSource ID="DSwaris" runat="server"

ConnectionString="<%$ ConnectionStrings:RDOCS %>"
                    ProviderName="<%$ ConnectionStrings:RDOCS.ProviderName %>"

SelectCommand="Select * from Trefmaster where

codenameref='BENEFICIARIES_RELATIONSHIP' order by sequenceno asc">
                </asp:SqlDataSource>

            </td>
        </tr>
code di atas melakukan proses Bind Langsung di filename.aspx akan saya rubah dengan melakukan di fileaspx.cs berikut perubahan codenya:



 <tr>
            <td style="height: 1px;" valign="middle">
                Hubungan dengan ahli waris
            </td>
            <td style="height: 1px;" valign="middle">
                :
            </td>
            <td style="height: 1px;" valign="middle">
                <asp:DropDownList ID="txthubwaris" runat="server" Width="294px" />
              
              

            </td>
        </tr>
        <tr>



dan pada file aspx.cs berikut codenya:

 private void BindAhliWarisDDL()
    {
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = myConn;
        cmd.CommandText = "SELECT CodeRef,[Desc]  FROM TRefMaster WHERE CodeNameRef = 'BENEFICIARIES_RELATIONSHIP'";
        try
        {
            myConn.Open();
            SqlDataReader J = cmd.ExecuteReader();
            txthubwaris.DataSource = J;
            txthubwaris.DataTextField = "Desc";
            txthubwaris.DataValueField = "CodeRef";
            txthubwaris.DataBind();
        }
        catch
        {
        }
        finally
        {
            if (myConn.State != ConnectionState.Closed)
                myConn.Close();
        }
    }

dan BindAhliWarisDDL() jangan lupa kita letakkan di pageload.