Ürfet Demirtaş - Tek bir konuda uzman olmak ! (.NET)
ANASAYFA | HAKKIMDA | ASP.NET | C# | CSS | JAVASCRİPT | GÜVENLİK | LİNQ | Ms SQL | İLETİŞİM
 
 
MAKALE ARA
   
SON EKLEDİĞİM 5 MAKELE
   
C# ile Excelden veri okuma  - 06.01.2012 09:40:13
Günlük hayatta veya isyerlerinde excel dosyalari sık sık kullanilir. Durum böyle olunca yaptıgımiz yazılımlarında excel dosyaları üzerinde islem yapabilmesi oldukça faydali olabilir. Lafi fala uzatmadan hemen konuya girelim ve excel dosyarindaki veriler C# dili ile nasil okunur onu anlamaya çalisalim.

Öncelikle bunun için bir tane Windows Form Uygulamasi olusturalim ve üstüne toolbaxtan birer tane TextBox, Buton, Datagridview ve OpenFileDialog koyalim. Butona tikladigimizda OpenFileDialog açilacak ve islem yapacagimiz excel dosyasini açacagiz. Dosyayi seçip Aç'a tiklayinca seçtigimiz dosya içindeki [sinif_listesi$] tablosunun içerigini arayüzdeki Giridview içerinde görecegiz.


Ilk olarak excele baglanabilmek için "using System.Data.OleDb;" 'yi ekleyelim. Daha sonra butonumuzun click event'i altinda gerekli kodlari yazalim.

private void btn_gozat_Click(object sender, EventArgs e)
{
     open_file_dialog.ShowDialog();
     txt_dosya_yolu.Text = open_file_dialog.FileName;
     string dosya_yolu= open_file_dialog.FileName;

     OleDbConnection baglanti = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; 
                                 Data Source="
+dosya_yolu+"; Extended Properties=Excel 12.0");
     baglanti.Open();
     string sorgu = "select * from [sinif_listesi$] ";
     OleDbDataAdapter data_adaptor = new OleDbDataAdapter(sorgu, baglanti);
     baglanti.Close();

    DataTable dt = new DataTable();
    data_adaptor.Fill(dt);
    grid_view.DataSource = dt;
           
}



Eger tabladaki tüm verileri almak istemiyorsaniz [sinif_listesi$] kisminda degisiklik yaparak istediginiz kisim lari alabilirsiniz.

Kaynak

ASP.NET textbox atlatma  - 20.12.2011 15:44:35

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<head runat="server">

    <script type="text/javascript" language="Javascript">
      function
atla(deger, karakter, alan)

              {if (deger.length >= karakter) { eval(alan).focus();}}
    </script>


</head>

<body>

<form id="form1" runat="server">

  <asp:TextBox ID="TextBox1" runat="server" onkeyup="atla(this.value,4,'document.form1.TextBox2');"></asp:TextBox>
  <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

</form>

</body>

</html>

 

ASP.NET Sayfa Yönlendirme / Yenileme  - 09.12.2011 14:07:09
Response.Redirect("SayfaAdi.aspx");

Response.Redirect("SayfaAdi.aspx?ID=" + Session["ID"]);
 
Page.Response.Redirect(Page.Request.Url.ToString(), true);
HTML (F5) Tuşunu Pasif Yapma  - 09.12.2011 14:04:42

<head>
<script>

function cancelRefresh()
{

// F5

if (window.event && window.event.keyCode == 116)
{
window.event.keyCode = 8;
}

// keycode for backspace

if (window.event && window.event.keyCode == 8)
{

//backspace window.event.cancelBubble = true;
window.event.returnValue = false; return false;

}
}

</script>
</head>

<body  ONKEYDOWN="return cancelRefresh()">
</body> 

 

ASP.NET Mobile Cihaz Kontrolü  - 07.12.2011 17:59:08

using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; 

namespace MobilKontrol
{

    public partial class _Default : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {

            if (this.IsMobile())
            {
                Response.Redirect("~/MobileSayfa.aspx");
            }
        } 

        public bool IsMobile()
        {

            string[] mobiles =

            new[]
               {
                                          "midp", "j2me", "avant", "docomo",

                    "novarra", "palmos", "palmsource",

                    "240x320", "opwv", "chtml",

                    "pda", "windows ce", "mmp/",

                    "blackberry", "mib/", "symbian",

                    "wireless", "nokia", "hand", "mobi",

                    "phone", "cdm", "up.b", "audio",

                    "SIE-", "SEC-", "samsung", "HTC",

                    "mot-", "mitsu", "sagem", "sony"

                    , "alcatel", "lg", "eric", "vx",

                    "NEC", "philips", "mmm", "xx",

                    "panasonic", "sharp", "wap", "sch",

                    "rover", "pocket", "benq", "java",

                    "pt", "pg", "vox", "amoi",

                    "bird", "compal", "kg", "voda",

                    "sany", "kdd", "dbt", "sendo",

                    "sgh", "gradi", "jb", "dddi",

                    "moto", "iphone"

                };
 

            foreach (string s in mobiles)
            {

                if (Request.ServerVariables["HTTP_USER_AGENT"].ToLower().Contains(s.ToLower()))
                {

                    return true;
                }

            } 

            return false;
        }

    }
}

Kaynak: http://www.codeproject.com/


Powered by Ürfet Demirtaş © Copyright 2010 - Kodlama C# .NET