datasource = select() den dönen datarow[] hatası

herhangi bir girdview veya combobox ın datasource’una datarow dizisi göndermek zorunda olduğumuzda hatayla karşılaşırız:

comboBox1.DataSource = dt.Select(“d<30”);

hatanın oluşma sebebi aşağıdaki interface lerden herhangi biriyle implemente olmayan nesneler datagrid gibi kontrollere datasource olarak bağlanamaz.

 

IList interface
IListSource interface
IBindingList interface
IBindingListView interface

Sorunu çözümü önce datasource olarak datatable’ı seçip ardından datatable’ın DefaultView.RowFilter özelliğine koşulumuzu eklemek:

comboBox1.DataSource = dt;
dt.DefaultView.RowFilter = “d<30”;

TC kimlik no doğruluk kontrolü

TcKimlikNo web servisi kapanıp ücretli bir hale geldikten sonraKimlik Numarası tesbiti yapmamız gereken durumlarda sıkıntıya düşüyoruz.

Fakat TC kimlik numaraları bir algoritmaya göre verildiği için basit formlarda kullanıcı’nın doğru kimlik numarası girip girmediğini tesbit etmek için şu metodu kullanabiliriz:


public bool TCKimlik(string no)
{
   if (no.Length != 11) { return false; }
   int sayi = 0;
   for (int i = 0; i < 10; i++) sayi += int.Parse(no.Substring(i, 1));
   return sayi.ToString().Substring(sayi.ToString().Length - 1, 1) == no.Substring(10, 1) ? true : false;
}

Algoritmanın temeli; ilk 10 rakamın toplamının onlar basamağı, 11. rakama eşit çıkmak zorunda,
Burada kullanıcı deneme yanılma yaparak doğru gösterebilir tabi, ama hiç yoktan iyidir…

Web.Config’de değer tutmak

Web uygulamalarımızda çoğu zaman değerini dışarıdan almaya ihtiyaç duyduğumuz değişkenler olur bunları tutmak için en iyi yöntem Web.Config içindeki appSettings bölümüdür.

<appSettings>
<add key=”HostName” value=”127.0.0.1″ />
</appSettings>

Eklediğimiz bu parametrenin değerine şu şekilde ulaşabiliriz:
VB.NET

AppSettings.Item(“HostName“)

C#.net

ConfigurationSettings.AppSettings[“HostName“].ToString();

Fakat bu sınıfı kullanabilmek için code sayfamızın başına System.Configuration.ConfigurationSettings namespace’ini eklememiz gerekiyor.
VB.NET

Imports System.Configuration.ConfigurationSettings

veya
C#.net

using System.Configuration.ConfigurationSettings;

ASP.net ile bir sitenin içeriğini almak

Bazen Döviz Bilgileri, Maçsonuçları gibi başka bir sitenin içeriğini almanız gerekebilir. Bunun için C# da aşağıdaki meddu kullanabilirsiniz:

public static string icerikAl(string url)

{

    WebRequest wReq = WebRequest.Create(url);

    wReq.Timeout = 10000; // zaman aşımı süresi

    WebResponse wRes = wReq.GetResponse();

    Encoding enc = Encoding.GetEncoding("iso-8859-9");

    StreamReader sRed = new StreamReader(wRes.GetResponseStream(), enc);

    return sRed.ReadToEnd();

}

lt01.text = icerikAl("http://www.goals365.com/feed/ soccer/index.php");

asp.net sayfalama

Asp.net ‘de datagridview kullandığımız zaman sayfalamayı .NET kendisi yapıyor ama listenizi kendiniz oluşturuyorsanız o zaman problemler çıkabiliyor.

Aşağıdaki metoda toplam sayfa sayısını,ekrandaki sayfayı ve gideceğimiz linkin ön ekini göndererek şu şekilde sayfalama oluşturabiliriz.sayfalama.gif

private static string sayfalamaYap(int ts, int es, string yol)

{//ts=toplam sayfa, es=ekrandaki sayfa, yol = link

    int eis = 0;

    int ess = 0;

    bool i2demi = (es – 6 < 1) ? true : false//ilk 2 sayfadan birindeysek true–not:-2 idi

    bool s2demi = (ts – 6 < es) ? true : false; //son 2 sayfadan birindeysek true

    bool imi = (es == 1) ? true : false;        //ilk sayfa isek true

    bool smu = (es == ts) ? true : false;      //son sayfa isek true

    string text = “<div id=\”paging\”>”;

    string buton = “<a href=\”/” + yol + “{0}\” class=\”{2}\”>{1}</a>”;

    if (i2demi & s2demi) { eis = 1; ess = ts; }

    else if (!i2demi & s2demi) { eis = ts – 8; ess = ts; }

    else if (i2demi & !s2demi) { eis = 1; ess = 8; }

    else { eis = es – 4; ess = es + 4; }

    if (!imi) { text += string.Format(buton, (es – 1).ToString(), “< previus”, “nav”); }

    if (!i2demi) { text += string.Format(buton, “1”, “1”, “nav”) + string.Format(buton, “2”, “2”, “nav”) + ” … “; }

    for (int i = eis; i <= ess; i++)

    {

        if (i == es) { text += “<span href=\”\” class=\”navnone\”>” + i.ToString() + “</span>”; }

        else { text += string.Format(buton, i.ToString(), i.ToString(), “nav”); }

    }

    if (!s2demi) { text += ” … “ + string.Format(buton, (ts – 1).ToString(), (ts – 1).ToString(), “nav”) + string.Format(buton, ts.ToString(), ts.ToString(), “nav”); }

    if (!smu) { text += string.Format(buton, (es + 1).ToString(), “next >”, “nav”); }

    return text + “</div>”;

}

 

Using C# & FFMPEG

Over the past 3 years, I’ve been searching extensively for a open-source (or low-cost) alternative for video conversion to the .flv format. This search typically leads directly to FFmpeg, an open source video compression and conversion tool. FFMPEG is umbelievably fast, and handles Flash Video without a problem. The biggest hurdle that I’ve run into when trying to design it into my applications is that it does not have a .NET interface and the open source libraries it uses are long and confusing. This week, however, I found a post on Daniel’s blog which contains a project that wraps the FFmpeglibraries. I haven’t gotten a chance to look at it too thoroughly, but it should definately open up the opportunity to make use of FFmpeg’s tools in a managed environment. Even if Daniel doesn’t take the project much further, it looks like a great start to a complete .NET FFmpeg library!

usefull links:
http://sourceforge.net/projects/sharpffmpeg
http://www.bytescout.com/ffmpegscout.html
http://www.iepak.com/2/TopicDetail.aspx