CryptoSuite.Org

Geri git   CryptoSuite.ORG || The Best Encryption Platform Of The World > Programlama > C#

C# C# Hakkında Herşey

Konu Bilgileri
Konu Başlığı
C# da örnek kodlar
Konudaki Cevap Sayısı
4
Şuan Bu Konuyu Görüntüleyenler
 
Görüntülenme Sayısı
114

Yeni Konu aç Cevapla
 
LinkBack Seçenekler Stil
Alt 08-23-09, 02:08   #1 (permalink)
Member
 
SUST@L1 - ait Kullanıcı Resmi (Avatar)

User ID : 4735
Messages : 20
Threads : 7
Thanks : 0
Rat :
SUST@L1 isimli Üye şimdilik offline konumundadır
CryptoSuite.Org
Standart C# da örnek kodlar

C# İle Gmail Hesabında Mail Gönderme


Gmail hesabına bağlanarak mail gönderebilmemizi sağlar



Kod:
 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Net;

using System.Net.Mail;

 

namespace EMail

{

public partial class MailGondermeFormu : Form

{

public MailGondermeFormu()

{

InitializeComponent();

}

 

static bool mailSent = false;

string[] GonderilenlerDizisi = new string[3];

public void SendMail()

{

System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();

msg.To.Add(txtKime.Text);

msg.From = new MailAddress(txtKimden.Text, txtKullaniciAdi.Text, System.Text.Encoding.UTF8);

msg.Subject = txtKonu.Text;

msg.SubjectEncoding = System.Text.Encoding.UTF8;

msg.Body = txtMesaj.Text;

msg.BodyEncoding = System.Text.Encoding.UTF8;

msg.IsBodyHtml = false;

msg.Priority = MailPriority.High;

if (txtEkDosya.Text != "")

{

msg.Attachments.Add(new Attachment(txtEkDosya.Text));

}

 

SmtpClient client = new SmtpClient();

client.Credentials = new System.Net.NetworkCredential(txtKullaniciAdi.Text, txtSifre.Text);

client.Port = 587;//or use 587 

client.Host = "smtp.gmail.com";

client.EnableSsl = true;

client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);

object userState = msg;

try

{

client.SendAsync(msg, userState);

}

catch (System.Net.Mail.SmtpException ex)

{

MessageBox.Show(ex.Message, "Mail Gönderme Hatası");

}

}

 

void client_SendCompleted(object sender, AsyncCompletedEventArgs e)

{

MailMessage mail = (MailMessage)e.UserState;

string subject = mail.Subject;

 

if (e.Cancelled)

{

string cancelled = string.Format("[{0}] Mail gönderme iptal edildi.", subject);

MessageBox.Show(cancelled);

}

if (e.Error != null)

{

string error = String.Format("[{0}] {1}", subject, e.Error.ToString());

MessageBox.Show(error);

}

else

{

MessageBox.Show("E-Mail başarıyla gönderildi.");

}

mailSent = true;

}

 

private void btnEkle_Click(object sender, EventArgs e)

{

openFileDialog1.ShowDialog();

if (openFileDialog1.FileName == "")

{

txtEkDosya.Text = "";

}

txtEkDosya.Text = openFileDialog1.FileName;

}

 

private void btnGonder_Click(object sender, EventArgs e)

{

this.SendMail();

}

 

private void btnTemizle_Click(object sender, EventArgs e)

{

for (int i = 0; i < groupBox1.Controls.Count; i++)

{

if (groupBox1.Controls[i] is TextBox)

{

groupBox1.Controls[i].ResetText();

}

}

}

}

}
  Alıntı ile Cevapla
Alt 08-23-09, 02:09   #2 (permalink)
Member
 
SUST@L1 - ait Kullanıcı Resmi (Avatar)

User ID : 4735
Messages : 20
Threads : 7
Thanks : 0
Rat :
SUST@L1 isimli Üye şimdilik offline konumundadır
CryptoSuite.Org
Standart C# da örnek kodlar

Visual C#.NET de Veritabanı İşlemleri


Exeldeki verileri veritabanımıza aktarmamızı sağlar.


Kod:
 

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.Data.OleDb; 

using ocx; 

 

namespace ocx

{

/// <summary>

/// Summary description for ExcelExport.

/// </summary>

public class ExcelExport : System.Windows.Forms.Form

{

private System.Windows.Forms.ComboBox cboSheetnames;

private System.Windows.Forms.TextBox txtRange;

private System.Windows.Forms.TextBox textBox1;

private System.Windows.Forms.Label label3;

private System.Windows.Forms.Label lblSheet;

private System.Windows.Forms.Button btnOpenFileDlg;

private System.Windows.Forms.Label lblFilename;

private System.Windows.Forms.DataGrid dataGrid1;

internal System.Windows.Forms.ProgressBar progressBar1;

private System.Windows.Forms.Button button1;

private System.Windows.Forms.Button btnGetData;

private DataTable _dt;

private string _strExcelFilename = "";

private ExcelReader _exr=null;

private int _intPKCol=-1;

private System.Windows.Forms.Button btnSetPK;

private System.Windows.Forms.Label label4;

private System.Windows.Forms.TextBox txtPK;

private System.Windows.Forms.Label label1;

private System.Windows.Forms.Label lblCellOperatorIs;

private System.Windows.Forms.Label lblGetValueData;

private System.Windows.Forms.TextBox txtCell;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

 

public ExcelExport()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

 

//

// TODO: Add any constructor code after InitializeComponent call

//

}

 

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if(components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

 

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ExcelExport));

this.cboSheetnames = new System.Windows.Forms.ComboBox();

this.txtRange = new System.Windows.Forms.TextBox();

this.textBox1 = new System.Windows.Forms.TextBox();

this.label3 = new System.Windows.Forms.Label();

this.lblSheet = new System.Windows.Forms.Label();

this.btnOpenFileDlg = new System.Windows.Forms.Button();

this.lblFilename = new System.Windows.Forms.Label();

this.dataGrid1 = new System.Windows.Forms.DataGrid();

this.progressBar1 = new System.Windows.Forms.ProgressBar();

this.button1 = new System.Windows.Forms.Button();

this.btnGetData = new System.Windows.Forms.Button();

this.btnSetPK = new System.Windows.Forms.Button();

this.label4 = new System.Windows.Forms.Label();

this.txtPK = new System.Windows.Forms.TextBox();

this.label1 = new System.Windows.Forms.Label();

this.lblCellOperatorIs = new System.Windows.Forms.Label();

this.lblGetValueData = new System.Windows.Forms.Label();

this.txtCell = new System.Windows.Forms.TextBox();

((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();

this.SuspendLayout();

// 

// cboSheetnames

// 

this.cboSheetnames................................. = new System.Drawing.Point(72, 32);

this.cboSheetnames.Name = "cboSheetnames";

this.cboSheetnames.Size = new System.Drawing.Size(121, 21);

this.cboSheetnames.TabIndex = 25;

// 

// txtRange

// 

this.txtRange................................. = new System.Drawing.Point(368, 32);

this.txtRange.MaxLength = 20;

this.txtRange.Name = "txtRange";

this.txtRange.Size = new System.Drawing.Size(72, 20);

this.txtRange.TabIndex = 24;

this.txtRange.Text = "A2:F6";

// 

// textBox1

// 

this.textBox1.Enabled = false;

this.textBox1................................. = new System.Drawing.Point(72, 8);

this.textBox1.Name = "textBox1";

this.textBox1.Size = new System.Drawing.Size(368, 20);

this.textBox1.TabIndex = 19;

// 

// label3

// 

this.label3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;

this.label3................................. = new System.Drawing.Point(200, 32);

this.label3.Name = "label3";

this.label3.Size = new System.Drawing.Size(167, 20);

this.label3.TabIndex = 23;

this.label3.Text = "Verinin Bulunduğu Hücre Aralığı";

this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

// 

// lblSheet

// 

this.lblSheet.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;

this.lblSheet................................. = new System.Drawing.Point(0, 32);

this.lblSheet.Name = "lblSheet";

this.lblSheet.Size = new System.Drawing.Size(72, 20);

this.lblSheet.TabIndex = 22;

this.lblSheet.Text = "Veri Sayfası";

this.lblSheet.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

// 

// btnOpenFileDlg

// 

this.btnOpenFileDlg.Image = ((System.Drawing.Image)(resources.GetObject("btnOpenFileDlg.Image")));

this.btnOpenFileDlg.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;

this.btnOpenFileDlg................................. = new System.Drawing.Point(448, 8);

this.btnOpenFileDlg.Name = "btnOpenFileDlg";

this.btnOpenFileDlg.Size = new System.Drawing.Size(48, 24);

this.btnOpenFileDlg.TabIndex = 21;

this.btnOpenFileDlg.Text = "Aç";

this.btnOpenFileDlg.TextAlign = System.Drawing.ContentAlignment.MiddleRight;

this.btnOpenFileDlg.Click += new System.EventHandler(this.btnOpenFileDlg_Click);

// 

// lblFilename

// 

this.lblFilename.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;

this.lblFilename................................. = new System.Drawing.Point(0, 8);

this.lblFilename.Name = "lblFilename";

this.lblFilename.Size = new System.Drawing.Size(72, 20);

this.lblFilename.TabIndex = 20;

this.lblFilename.Text = "Dosya Yolu";

this.lblFilename.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

// 

// dataGrid1

// 

this.dataGrid1.AlternatingBackColor = System.Drawing.Color.GhostWhite;

this.dataGrid1.BackColor = System.Drawing.Color.GhostWhite;

this.dataGrid1.BackgroundColor = System.Drawing.Color.Lavender;

this.dataGrid1.CaptionBackColor = System.Drawing.Color.RoyalBlue;

this.dataGrid1.CaptionFont = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(162)));

this.dataGrid1.CaptionForeColor = System.Drawing.Color.White;

this.dataGrid1.CaptionText = " EXCEL DOSYASINDAN OKUNAN KAYITLAR";

this.dataGrid1.DataMember = "";

this.dataGrid1.FlatMode = true;

this.dataGrid1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F);

this.dataGrid1.ForeColor = System.Drawing.Color.MidnightBlue;

this.dataGrid1.GridLineColor = System.Drawing.Color.RoyalBlue;

this.dataGrid1.HeaderBackColor = System.Drawing.Color.MidnightBlue;

this.dataGrid1.HeaderFont = new System.Drawing.Font("Microsoft Sans Serif", 8F);

this.dataGrid1.HeaderForeColor = System.Drawing.Color.Lavender;

this.dataGrid1.LinkColor = System.Drawing.Color.Teal;

this.dataGrid1................................. = new System.Drawing.Point(0, 64);

this.dataGrid1.Name = "dataGrid1";

this.dataGrid1.ParentRowsBackColor = System.Drawing.Color.Lavender;

this.dataGrid1.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;

this.dataGrid1.ReadOnly = true;

this.dataGrid1.SelectionBackColor = System.Drawing.Color.Teal;

this.dataGrid1.SelectionForeColor = System.Drawing.Color.PaleGreen;

this.dataGrid1.Size = new System.Drawing.Size(496, 216);

this.dataGrid1.TabIndex = 26;

this.dataGrid1.Navigate += new System.Windows.Forms.NavigateEventHandler(this.dataGrid1_Navigate);

// 

// progressBar1

// 

this.progressBar1................................. = new System.Drawing.Point(0, 288);

this.progressBar1.Name = "progressBar1";

this.progressBar1.Size = new System.Drawing.Size(256, 24);

this.progressBar1.TabIndex = 29;

this.progressBar1.Visible = false;

// 

// button1

// 

this.button1.Enabled = false;

this.button1................................. = new System.Drawing.Point(272, 288);

this.button1.Name = "button1";

this.button1.Size = new System.Drawing.Size(104, 24);

this.button1.TabIndex = 28;

this.button1.Text = "Veritabanına yaz";

this.button1.Click += new System.EventHandler(this.button1_Click);

// 

// btnGetData

// 

this.btnGetData.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));

this.btnGetData................................. = new System.Drawing.Point(384, 288);

this.btnGetData.Name = "btnGetData";

this.btnGetData.Size = new System.Drawing.Size(112, 24);

this.btnGetData.TabIndex = 27;

this.btnGetData.Text = "Excel\'den Veri Oku";

this.btnGetData.Click += new System.EventHandler(this.btnGetData_Click);

// 

// btnSetPK

// 

this.btnSetPK.Enabled = false;

this.btnSetPK................................. = new System.Drawing.Point(136, 472);

this.btnSetPK.Name = "btnSetPK";

this.btnSetPK.Size = new System.Drawing.Size(76, 24);

this.btnSetPK.TabIndex = 32;

this.btnSetPK.TabStop = false;

this.btnSetPK.Text = "Set PK";

this.btnSetPK.Visible = false;

// 

// label4

// 

this.label4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;

this.label4................................. = new System.Drawing.Point(0, 472);

this.label4.Name = "label4";

this.label4.Size = new System.Drawing.Size(78, 20);

this.label4.TabIndex = 31;

this.label4.Text = "Birincil Sütun";

this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

this.label4.Visible = false;

// 

// txtPK

// 

this.txtPK.Enabled = false;

this.txtPK................................. = new System.Drawing.Point(80, 472);

this.txtPK.MaxLength = 3;

this.txtPK.Name = "txtPK";

this.txtPK.Size = new System.Drawing.Size(47, 20);

this.txtPK.TabIndex = 30;

this.txtPK.TabStop = false;

this.txtPK.Text = "0";

this.txtPK.Visible = false;

// 

// label1

// 

this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;

this.label1.Enabled = false;

this.label1................................. = new System.Drawing.Point(0, 496);

this.label1.Name = "label1";

this.label1.Size = new System.Drawing.Size(48, 20);

this.label1.TabIndex = 36;

this.label1.Text = "Cell";

this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

// 

// lblCellOperatorIs

// 

this.lblCellOperatorIs.Enabled = false;

this.lblCellOperatorIs................................. = new System.Drawing.Point(120, 496);

this.lblCellOperatorIs.Name = "lblCellOperatorIs";

this.lblCellOperatorIs.Size = new System.Drawing.Size(8, 12);

this.lblCellOperatorIs.TabIndex = 34;

this.lblCellOperatorIs.Text = "=";

// 

// lblGetValueData

// 

this.lblGetValueData.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;

this.lblGetValueData.Enabled = false;

this.lblGetValueData................................. = new System.Drawing.Point(136, 496);

this.lblGetValueData.Name = "lblGetValueData";

this.lblGetValueData.Size = new System.Drawing.Size(144, 20);

this.lblGetValueData.TabIndex = 33;

this.lblGetValueData.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

// 

// txtCell

// 

this.txtCell.Enabled = false;

this.txtCell................................. = new System.Drawing.Point(56, 496);

this.txtCell.MaxLength = 4;

this.txtCell.Name = "txtCell";

this.txtCell.Size = new System.Drawing.Size(48, 20);

this.txtCell.TabIndex = 35;

this.txtCell.TabStop = false;

this.txtCell.Text = "A2";

// 

// ExcelExport

// 

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(496, 319);

this.Controls.Add(this.label1);

this.Controls.Add(this.lblCellOperatorIs);

this.Controls.Add(this.lblGetValueData);

this.Controls.Add(this.txtCell);

this.Controls.Add(this.txtPK);

this.Controls.Add(this.txtRange);

this.Controls.Add(this.textBox1);

this.Controls.Add(this.btnSetPK);

this.Controls.Add(this.label4);

this.Controls.Add(this.progressBar1);

this.Controls.Add(this.button1);

this.Controls.Add(this.btnGetData);

this.Controls.Add(this.dataGrid1);

this.Controls.Add(this.cboSheetnames);

this.Controls.Add(this.label3);

this.Controls.Add(this.lblSheet);

this.Controls.Add(this.btnOpenFileDlg);

this.Controls.Add(this.lblFilename);

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;

this.Name = "ExcelExport";

this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

this.Text = "ExcelExport";

this.Load += new System.EventHandler(this.ExcelExport_Load);

((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();

this.ResumeLayout(false);

this.PerformLayout();

 

}

#endregion

 

private void btnOpenFileDlg_Click(object sender, System.EventArgs e)

{

OpenFileDialog f = new OpenFileDialog(); 

f.Filter ="Excel files | *.xls";

f.InitialDirectory = Application.ExecutablePath; 

 

if (f.ShowDialog()==DialogResult.OK)

if (f.FileName != null && f.CheckFileExists==true )

{

this._strExcelFilename =f.FileName;

this.textBox1.Text = f.FileName;

RetrieveSheetnames();

if (this.cboSheetnames.Items.Count >0) 

cboSheetnames.SelectedIndex =0;

}

}

private void InitExcel(ref ExcelReader exr)

{

//Excel must be open

if (exr == null)

{

exr = new ExcelReader();

exr.ExcelFilename = _strExcelFilename;

exr.Headers =false;

exr.MixedData =true;

}

if (_dt==null) _dt = new DataTable("par"); 

exr.KeepConnectionOpen =true;

 

//Check excel sheetname is selected

if (this.cboSheetnames.SelectedIndex>-1) 

exr.SheetName = this.cboSheetnames.Text; 

else

throw new Exception("Bilgilerin olduğu sayfayı seçmelisiniz!"); 

cboSheetnames.Focus();

 

//Set excel sheet range

exr.SheetRange = this.txtRange.Text; 

 

 

}

 

private void button1_Click(object sender, System.EventArgs e)

{

DataRow[] Satirlar;

Satirlar = _dt.Select();

int Satir=Satirlar.Length;

int i=0;

 

progressBar1.Minimum = 0;

progressBar1.Maximum = Satir;

progressBar1.Visible = true;

for(i=0;i<Satir;i++)

{

System.Data.DataRow ekle;

cb=new OleDbCommandBuilder(adp);

ekle=dt.Tables["IZIN"].NewRow();

progressBar1.Value = i;

 

ekle["Sicil"]=Satirlar[i].ItemArray[0];

ekle["Adi"]=Satirlar[i].ItemArray[1];

ekle["Soyadi"]=Satirlar[i].ItemArray[2];

ekle["Unvan"]=Satirlar[i].ItemArray[3];

ekle["HizmetSuresi"]=Satirlar[i].ItemArray[4];

ekle["Servis"]=Satirlar[i].ItemArray[5];

dt.Tables["IZIN"].Rows.Add(ekle);

adp.Update(dt, "IZIN");

Application.DoEvents();

}

button1.Enabled=false;

MessageBox.Show (" " + Satir.ToString() + " adet personel kaydı veritabanına işlendi.", "İŞLEM TAMAM");

progressBar1.Visible = false;

}

 

OleDbConnection odc;

OleDbDataAdapter adp;

DataSet dt;

OleDbCommandBuilder cb;//

private void ExcelExport_Load(object sender, System.EventArgs e)

{

string baglanti = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath.ToString() + "\\Kutuk.mdb";

string sorgu="SELECT * FROM IZIN";

odc = new OleDbConnection(baglanti);

adp = new OleDbDataAdapter(sorgu,odc);

dt=new DataSet();

 

adp.Fill(dt, "IZIN");

 

if (System.IO.File.Exists(this.textBox1.Text))

RetrieveSheetnames();

}

private void RetrieveSheetnames()

{

try

{

this.cboSheetnames.Items.Clear();

 

if (_exr !=null)

{

_exr.Dispose();

_exr=null;

}

 

_exr = new ExcelReader();

_exr.ExcelFilename = _strExcelFilename;

_exr.Headers =false;

_exr.MixedData =true;

string[] sheetnames = this._exr.GetExcelSheetNames();

this.cboSheetnames.Items.AddRange(sheetnames); 

}

catch (Exception ex)

{

MessageBox.Show(ex.Message,"HATA",MessageBoxButtons.OK,MessageBoxIcon.Error); 

}

}

 

private void btnGetData_Click(object sender, System.EventArgs e)

{

try

{

Cursor = Cursors.WaitCursor; 

InitExcel(ref _exr);

_dt = _exr.GetTable();

this.lblGetValueData.Text = _exr.GetValue(txtCell.Text).ToString() ;

this.dataGrid1.DataSource=_dt;

 

_exr.Close();

_exr.Dispose();

_exr=null;

Cursor = Cursors.Default;

if (_dt !=null && this.txtPK.Text.Length >0) SetPK();

 

DataRow[] SatirlarS;

SatirlarS = _dt.Select();

int SatirS=SatirlarS.Length;

 

button1.Enabled=true;

btnGetData.Enabled=false;

MessageBox.Show (" " + SatirS.ToString() + " adet personel kaydı okundu!", "OKUNAN KAYIT SAYISI");

 

} 

catch (Exception ex)

{

Cursor = Cursors.Default;

MessageBox.Show(ex.Message,"HATA",MessageBoxButtons.OK,MessageBoxIcon.Error); 

}

}

private bool IsInt(string strNr)

{

try

{

int intNr= int.Parse(strNr);

return true;

 

}

catch

{

return false;

}

}

private void SetPK()

{

Cursor = Cursors.WaitCursor; 

_intPKCol=-1;

try

{

if (txtPK.Text.Length >0) 

{

if (IsInt(txtPK.Text)) 

_intPKCol=Convert.ToInt32(txtPK.Text) ;

else

{

if (_dt.Columns.Contains(txtPK.Text))

{

_intPKCol = _dt.Columns[txtPK.Text].Ordinal; 

}

else

{

throw new Exception("Columnname is not present in the table.!");

 

}

}

if (_dt.Columns.Count<=_intPKCol)

{

_intPKCol=-1;

Cursor = Cursors.Default;

throw new Exception("Column does not exists!");

}

}

Cursor = Cursors.Default;

}

 

catch (Exception ex)

{

Cursor = Cursors.Default;

MessageBox.Show(ex.Message,"HATA",MessageBoxButtons.OK,MessageBoxIcon.Error); 

}

}

 

private void dataGrid1_Navigate(object sender, NavigateEventArgs ne)

{

 

}

}

}
  Alıntı ile Cevapla
Alt 08-23-09, 02:11   #3 (permalink)
Member
 
SUST@L1 - ait Kullanıcı Resmi (Avatar)

User ID : 4735
Messages : 20
Threads : 7
Thanks : 0
Rat :
SUST@L1 isimli Üye şimdilik offline konumundadır
CryptoSuite.Org
Standart C# da örnek kodlar

Visual C#.NET de Veritabanı İşlemleri-2


Veritabanımızda ekle-sil-yenile-bul-güncelle-exel'e gönder işlemlerini yapmamızı sağlar


Kod:
 

using System;

using System.Drawing;

using System.Drawing.Printing;

using System.IO;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.Data.OleDb;

using System.Runtime.InteropServices;

using Office = Microsoft.Office.Core;

 

 

namespace ocx

{

/// <summary>

/// Summary description for Form1.

/// </summary>

public class Form1 : System.Windows.Forms.Form

{

private System.Windows.Forms.DataGrid dataGrid1;

private System.Windows.Forms.TextBox textBox1;

private System.Windows.Forms.TextBox textBox2;

private System.Windows.Forms.TextBox textBox3;

private System.Windows.Forms.TextBox textBox4;

private System.Windows.Forms.TextBox textBox5;

private System.Windows.Forms.TextBox textBox6;

private System.Windows.Forms.TextBox textBox7;

private System.Windows.Forms.Label label1;

private System.Windows.Forms.Label label2;

private System.Windows.Forms.Label label3;

private System.Windows.Forms.Label label4;

private System.Windows.Forms.Label label5;

private System.Windows.Forms.Label label6;

private System.Windows.Forms.Label label7;

private System.Windows.Forms.Button button1;

private System.Windows.Forms.GroupBox groupBox1;

private System.Windows.Forms.Button temizle;

private System.Windows.Forms.Button sil;

private System.Windows.Forms.Button kayit;

private System.Windows.Forms.Button bul;

private System.Windows.Forms.Button güncelle;

private System.Windows.Forms.Button button2;

private System.Windows.Forms.Button button4;

private System.Windows.Forms.Timer timer1;

private System.ComponentModel.IContainer components;

 

public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

 

 

//

// TODO: Add any constructor code after InitializeComponent call

//

}

 

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null) 

{

components.Dispose();

}

}

base.Dispose( disposing );

}

 

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.components = new System.ComponentModel.Container();

System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));

this.dataGrid1 = new System.Windows.Forms.DataGrid();

this.textBox1 = new System.Windows.Forms.TextBox();

this.textBox2 = new System.Windows.Forms.TextBox();

this.textBox3 = new System.Windows.Forms.TextBox();

this.textBox4 = new System.Windows.Forms.TextBox();

this.textBox5 = new System.Windows.Forms.TextBox();

this.textBox6 = new System.Windows.Forms.TextBox();

this.textBox7 = new System.Windows.Forms.TextBox();

this.label1 = new System.Windows.Forms.Label();

this.label2 = new System.Windows.Forms.Label();

this.label3 = new System.Windows.Forms.Label();

this.label4 = new System.Windows.Forms.Label();

this.label5 = new System.Windows.Forms.Label();

this.label6 = new System.Windows.Forms.Label();

this.label7 = new System.Windows.Forms.Label();

this.button1 = new System.Windows.Forms.Button();

this.groupBox1 = new System.Windows.Forms.GroupBox();

this.button4 = new System.Windows.Forms.Button();

this.button2 = new System.Windows.Forms.Button();

this.temizle = new System.Windows.Forms.Button();

this.sil = new System.Windows.Forms.Button();

this.kayit = new System.Windows.Forms.Button();

this.bul = new System.Windows.Forms.Button();

this.güncelle = new System.Windows.Forms.Button();

this.timer1 = new System.Windows.Forms.Timer(this.components);

((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();

this.groupBox1.SuspendLayout();

this.SuspendLayout();

// 

// dataGrid1

// 

this.dataGrid1.BackgroundColor = System.Drawing.SystemColors.Info;

this.dataGrid1.CaptionBackColor = System.Drawing.Color.LightSkyBlue;

this.dataGrid1.CaptionForeColor = System.Drawing.SystemColors.ControlText;

this.dataGrid1.CaptionText = " KAYITLI PERSONELLER";

this.dataGrid1.DataMember = "";

this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;

this.dataGrid1................................. = new System.Drawing.Point(8, 104);

this.dataGrid1.Name = "dataGrid1";

this.dataGrid1.Size = new System.Drawing.Size(520, 160);

this.dataGrid1.TabIndex = 0;

this.dataGrid1.DoubleClick += new System.EventHandler(this.dataGrid1_DoubleClick);

this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);

this.dataGrid1.Navigate += new System.Windows.Forms.NavigateEventHandler(this.dataGrid1_Navigate);

// 

// textBox1

// 

this.textBox1.BackColor = System.Drawing.SystemColors.Info;

this.textBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(162)));

this.textBox1.ForeColor = System.Drawing.Color.Red;

this.textBox1................................. = new System.Drawing.Point(96, 8);

this.textBox1.Name = "textBox1";

this.textBox1.ReadOnly = true;

this.textBox1.Size = new System.Drawing.Size(72, 21);

this.textBox1.TabIndex = 2;

// 

// textBox2

// 

this.textBox2................................. = new System.Drawing.Point(96, 32);

this.textBox2.Name = "textBox2";

this.textBox2.Size = new System.Drawing.Size(72, 20);

this.textBox2.TabIndex = 3;

// 

// textBox3

// 

this.textBox3................................. = new System.Drawing.Point(96, 56);

this.textBox3.Name = "textBox3";

this.textBox3.Size = new System.Drawing.Size(144, 20);

this.textBox3.TabIndex = 4;

// 

// textBox4

// 

this.textBox4................................. = new System.Drawing.Point(96, 80);

this.textBox4.Name = "textBox4";

this.textBox4.Size = new System.Drawing.Size(144, 20);

this.textBox4.TabIndex = 5;

// 

// textBox5

// 

this.textBox5................................. = new System.Drawing.Point(336, 8);

this.textBox5.Name = "textBox5";

this.textBox5.Size = new System.Drawing.Size(144, 20);

this.textBox5.TabIndex = 6;

// 

// textBox6

// 

this.textBox6................................. = new System.Drawing.Point(336, 32);

this.textBox6.Name = "textBox6";

this.textBox6.Size = new System.Drawing.Size(56, 20);

this.textBox6.TabIndex = 7;

// 

// textBox7

// 

this.textBox7................................. = new System.Drawing.Point(336, 56);

this.textBox7.Name = "textBox7";

this.textBox7.Size = new System.Drawing.Size(136, 20);

this.textBox7.TabIndex = 8;

// 

// label1

// 

this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;

this.label1................................. = new System.Drawing.Point(8, 32);

this.label1.Name = "label1";

this.label1.Size = new System.Drawing.Size(80, 20);

this.label1.TabIndex = 13;

this.label1.Text = "Sicil";

this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

// 

// label2

// 

this.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;

this.label2................................. = new System.Drawing.Point(8, 56);

this.label2.Name = "label2";

this.label2.Size = new System.Drawing.Size(80, 20);

this.label2.TabIndex = 14;

this.label2.Text = "Adı";

this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

// 

// label3

// 

this.label3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;

this.label3................................. = new System.Drawing.Point(8, 80);

this.label3.Name = "label3";

this.label3.Size = new System.Drawing.Size(80, 20);

this.label3.TabIndex = 15;

this.label3.Text = "Soyadı";

this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

// 

// label4

// 

this.label4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;

this.label4................................. = new System.Drawing.Point(248, 8);

this.label4.Name = "label4";

this.label4.Size = new System.Drawing.Size(80, 20);

this.label4.TabIndex = 16;

this.label4.Text = "Ünvan";

this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

// 

// label5

// 

this.label5.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;

this.label5................................. = new System.Drawing.Point(248, 32);

this.label5.Name = "label5";

this.label5.Size = new System.Drawing.Size(80, 20);

this.label5.TabIndex = 17;

this.label5.Text = "Hizmet Süresi";

this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

// 

// label6

// 

this.label6.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;

this.label6................................. = new System.Drawing.Point(248, 56);

this.label6.Name = "label6";

this.label6.Size = new System.Drawing.Size(80, 20);

this.label6.TabIndex = 18;

this.label6.Text = "Servis";

this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

// 

// label7

// 

this.label7.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;

this.label7................................. = new System.Drawing.Point(8, 8);

this.label7.Name = "label7";

this.label7.Size = new System.Drawing.Size(80, 20);

this.label7.TabIndex = 19;

this.label7.Text = "Sıra No";

this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

// 

// button1

// 

this.button1.BackColor = System.Drawing.Color.AliceBlue;

this.button1................................. = new System.Drawing.Point(80, 64);

this.button1.Name = "button1";

this.button1.Size = new System.Drawing.Size(104, 24);

this.button1.TabIndex = 20;

this.button1.Text = "Excel\'e Gönder";

this.button1.UseVisualStyleBackColor = false;

this.button1.Click += new System.EventHandler(this.button1_Click);

// 

// groupBox1

// 

this.groupBox1.BackColor = System.Drawing.SystemColors.InactiveCaption;

this.groupBox1.Controls.Add(this.button4);

this.groupBox1.Controls.Add(this.button2);

this.groupBox1.Controls.Add(this.temizle);

this.groupBox1.Controls.Add(this.sil);

this.groupBox1.Controls.Add(this.kayit);

this.groupBox1.Controls.Add(this.bul);

this.groupBox1.Controls.Add(this.güncelle);

this.groupBox1.Controls.Add(this.button1);

this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;

this.groupBox1................................. = new System.Drawing.Point(96, 280);

this.groupBox1.Name = "groupBox1";

this.groupBox1.Size = new System.Drawing.Size(432, 96);

this.groupBox1.TabIndex = 22;

this.groupBox1.TabStop = false;

// 

// button4

// 

this.button4.BackColor = System.Drawing.Color.Bisque;

this.button4................................. = new System.Drawing.Point(8, 16);

this.button4.Name = "button4";

this.button4.Size = new System.Drawing.Size(64, 24);

this.button4.TabIndex = 27;

this.button4.Text = "Yenile";

this.button4.UseVisualStyleBackColor = false;

this.button4.Click += new System.EventHandler(this.button4_Click);

// 

// button2

// 

this.button2.BackColor = System.Drawing.Color.AliceBlue;

this.button2................................. = new System.Drawing.Point(216, 64);

this.button2.Name = "button2";

this.button2.Size = new System.Drawing.Size(112, 24);

this.button2.TabIndex = 26;

this.button2.Text = "Excel\'den Al";

this.button2.UseVisualStyleBackColor = false;

this.button2.Click += new System.EventHandler(this.button2_Click);

// 

// temizle

// 

this.temizle.BackColor = System.Drawing.Color.Bisque;

this.temizle................................. = new System.Drawing.Point(80, 16);

this.temizle.Name = "temizle";

this.temizle.Size = new System.Drawing.Size(64, 24);

this.temizle.TabIndex = 17;

this.temizle.Text = "Temizle";

this.temizle.UseVisualStyleBackColor = false;

this.temizle.Click += new System.EventHandler(this.temizle_Click);

// 

// sil

// 

this.sil.BackColor = System.Drawing.Color.Bisque;

this.sil................................. = new System.Drawing.Point(368, 16);

this.sil.Name = "sil";

this.sil.Size = new System.Drawing.Size(56, 24);

this.sil.TabIndex = 16;

this.sil.Text = "Sil";

this.sil.UseVisualStyleBackColor = false;

this.sil.Click += new System.EventHandler(this.sil_Click);

// 

// kayit

// 

this.kayit.BackColor = System.Drawing.Color.Bisque;

this.kayit................................. = new System.Drawing.Point(296, 16);

this.kayit.Name = "kayit";

this.kayit.Size = new System.Drawing.Size(64, 24);

this.kayit.TabIndex = 15;

this.kayit.Text = "Kayıt";

this.kayit.UseVisualStyleBackColor = false;

this.kayit.Click += new System.EventHandler(this.kayit_Click);

// 

// bul

// 

this.bul.BackColor = System.Drawing.Color.Bisque;

this.bul................................. = new System.Drawing.Point(152, 16);

this.bul.Name = "bul";

this.bul.Size = new System.Drawing.Size(64, 24);

this.bul.TabIndex = 14;

this.bul.Text = "Bul";

this.bul.UseVisualStyleBackColor = false;

this.bul.Click += new System.EventHandler(this.bul_Click);

// 

// güncelle

// 

this.güncelle.BackColor = System.Drawing.Color.Bisque;

this.güncelle................................. = new System.Drawing.Point(224, 16);

this.güncelle.Name = "güncelle";

this.güncelle.Size = new System.Drawing.Size(64, 24);

this.güncelle.TabIndex = 13;

this.güncelle.Text = "Güncelle";

this.güncelle.UseVisualStyleBackColor = false;

this.güncelle.Click += new System.EventHandler(this.güncelle_Click);

// 

// timer1

// 

this.timer1.Tick += new System.EventHandler(this.timer1_Tick);

// 

// Form1

// 

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.BackColor = System.Drawing.SystemColors.Control;

this.ClientSize = new System.Drawing.Size(536, 381);

this.Controls.Add(this.groupBox1);

this.Controls.Add(this.label7);

this.Controls.Add(this.label6);

this.Controls.Add(this.label5);

this.Controls.Add(this.label4);

this.Controls.Add(this.label3);

this.Controls.Add(this.label2);

this.Controls.Add(this.label1);

this.Controls.Add(this.textBox7);

this.Controls.Add(this.textBox6);

this.Controls.Add(this.textBox5);

this.Controls.Add(this.textBox4);

this.Controls.Add(this.textBox3);

this.Controls.Add(this.textBox2);

this.Controls.Add(this.textBox1);

this.Controls.Add(this.dataGrid1);

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;

this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));

this.IsMdiContainer = true;

this.MaximizeBox = false;

this.Name = "Form1";

this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

this.Text = "Form1";

this.Load += new System.EventHandler(this.Form1_Load);

((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();

this.groupBox1.ResumeLayout(false);

this.ResumeLayout(false);

this.PerformLayout();

 

}

#endregion

 

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main() 

{

Application.Run(new Form1());

}

 

OleDbConnection odc;

OleDbDataAdapter adp;

DataSet dt;

OleDbCommandBuilder cb;// OleDbDataAdapter'i silme, güncelleme ve kayıt'a hazır hale getirmek için

private void Form1_Load(object sender, System.EventArgs e)

{

this.Text = " ** Hazırlayan: Ahmet Ali Süzen** ";

timer1.Interval = 100;

timer1.Enabled = true;

 

string baglanti = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath.ToString() + "\\Kutuk.mdb";

string sorgu="SELECT * FROM IZIN";

odc = new OleDbConnection(baglanti);

adp = new OleDbDataAdapter(sorgu,odc);

dt=new DataSet();

 

adp.Fill(dt, "IZIN");

dataGrid1.ReadOnly=true;

dataGrid1.CaptionText="KAYITLI PERSONELLER";

dataGrid1.DataSource = dt.Tables[0];

}

 

private void dataGrid1_DoubleClick(object sender, System.EventArgs e)

{

textBox1.DataBindings.Clear();

textBox2.DataBindings.Clear();

textBox3.DataBindings.Clear();

textBox4.DataBindings.Clear();

textBox5.DataBindings.Clear();

textBox6.DataBindings.Clear();

textBox7.DataBindings.Clear();

textBox1.DataBindings.Add("Text", dt.Tables[0],"ID");

textBox2.DataBindings.Add("Text", dt.Tables[0],"Sicil");

textBox3.DataBindings.Add("Text", dt.Tables[0],"Adi");

textBox4.DataBindings.Add("Text", dt.Tables[0],"Soyadi");

textBox5.DataBindings.Add("Text", dt.Tables[0],"Unvan");

textBox6.DataBindings.Add("Text", dt.Tables[0],"HizmetSuresi");

textBox7.DataBindings.Add("Text", dt.Tables[0],"Servis");

textBox2.Focus();

}

 

private void güncelle_Click(object sender, System.EventArgs e)

{

CurrencyManager sonraki=

(CurrencyManager)this.BindingContext[dt.Tables["IZIN"]];

sonraki.EndCurrentEdit();

cb=new OleDbCommandBuilder(adp); // OleDbDataAdapter'i silme, güncelleme ve kayıt'a hazır hale getirmek için

adp.Update(dt, "IZIN"); 

dt.Clear(); 

adp.Fill(dt.Tables[0]);

 

dataGrid1.DataSource = dt.Tables[0];

MessageBox.Show (" Güncelleme tamamlandı!", "İŞLEM TAMAM");

}

 

private void bul_Click(object sender, System.EventArgs e)

{

int kayit=0;

CurrencyManager yonet=

(CurrencyManager)this.BindingContext[dt.Tables["IZIN"]];

foreach(DataRow satir in dt.Tables[0].Rows)

{

if(satir["Sicil"].ToString()==textBox2.Text)

{

yonet.Position = kayit;

textBox1.DataBindings.Clear();

textBox2.DataBindings.Clear();

textBox3.DataBindings.Clear();

textBox4.DataBindings.Clear();

textBox5.DataBindings.Clear();

textBox6.DataBindings.Clear();

textBox7.DataBindings.Clear();

textBox1.DataBindings.Add("Text", dt.Tables[0],"ID");

textBox2.DataBindings.Add("Text", dt.Tables[0],"Sicil");

textBox3.DataBindings.Add("Text", dt.Tables[0],"Adi");

textBox4.DataBindings.Add("Text", dt.Tables[0],"Soyadi");

textBox5.DataBindings.Add("Text", dt.Tables[0],"Unvan");

textBox6.DataBindings.Add("Text", dt.Tables[0],"HizmetSuresi");

textBox7.DataBindings.Add("Text", dt.Tables[0],"Servis");

textBox2.Focus();

return;

}

kayit++;

if(kayit>dt.Tables["IZIN"].Rows.Count-1)

{

MessageBox.Show (" Aradığınız SİCİL NO'lu personele ait izin kaydı bulunamadı!");

textBox1.Focus();

}

}

}

 

private void kayit_Click(object sender, System.EventArgs e)

{

System.Data.DataRow ekle;

cb=new OleDbCommandBuilder(adp); // OleDbDataAdapter'i silme, güncelleme ve kayıt'a hazır hale getirmek için

 

ekle=dt.Tables["IZIN"].NewRow();

 

ekle["Sicil"]=textBox2.Text;

ekle["Adi"]=textBox3.Text;

ekle["Soyadi"]=textBox4.Text;

ekle["Unvan"]=textBox5.Text;

ekle["HizmetSuresi"]=textBox6.Text;

ekle["Servis"]=textBox7.Text;

 

dt.Tables["IZIN"].Rows.Add(ekle);

adp.Update(dt, "IZIN");

dt.Clear(); 

adp.Fill(dt.Tables[0]);

dataGrid1.DataSource = dt.Tables[0];

MessageBox.Show (" Kayıt tamamlandı!", "İŞLEM TAMAM");

}

 

private void sil_Click(object sender, System.EventArgs e)

{

 

CurrencyManager sonraki=

(CurrencyManager)this.BindingContext[dt.Tables["IZIN"]];

DialogResult uyar;

uyar=MessageBox.Show(this, textBox2.Text +" Sicil'li Personel Kaydını Silmek istiyor musunuz?", "SİLME UYARISI", MessageBoxButtons.YesNo, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2);

if(uyar==DialogResult.Yes)

{

cb=new OleDbCommandBuilder(adp); // OleDbDataAdapter'i silme, güncelleme ve kayıt'a hazır hale getirmek için

sonraki.RemoveAt(sonraki.Position);

adp.Update(dt, "IZIN");

dt.Clear(); 

adp.Fill(dt.Tables[0]);

dataGrid1.DataSource = dt.Tables[0];

MessageBox.Show (" Kayıt silindi!", "İŞLEM TAMAM");

}

else

{

MessageBox.Show(" Silme işlemi İptal edildi!");

}

}

 

private void temizle_Click(object sender, System.EventArgs e)

{

textBox1.DataBindings.Clear();

textBox2.DataBindings.Clear();

textBox3.DataBindings.Clear();

textBox4.DataBindings.Clear();

textBox5.DataBindings.Clear();

textBox6.DataBindings.Clear();

textBox7.DataBindings.Clear();

textBox1.Text="";

textBox2.Text="";

textBox3.Text="";

textBox4.Text="";

textBox5.Text="";

textBox6.Text="";

textBox7.Text="";

 

dt.Clear(); 

adp.Fill(dt.Tables[0]);

dataGrid1.DataSource = dt.Tables[0];

 

textBox2.Focus();

}

 

private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)

{

//dataGridde tıkladığımız satırın tümünün seçilmesi için

dataGrid1.UnSelect (dataGrid1.CurrentRowIndex );

int i=dataGrid1.CurrentRowIndex ; 

try

{

dataGrid1.Select (i);

}

catch

{

dataGrid1.Select ();

}

}

 

private void kapandı2(object sender, System.EventArgs e )

{

f2 = null;

}

ExcelExport f2;

private void button2_Click(object sender, System.EventArgs e)

{

if (f2 == null) //form değişkeni bir nesneyi göstermiyorsa

{

f2 = new ExcelExport(); //Yeni form oluştur

f2.Closed += new EventHandler(kapandı2);

f2.Text="EXCEL SAYFASINDAN VERİ ÇEKME / VERİTABANINA İŞLEME";

f2.Show();

}

else

//form zaten varsa öne getir

f2.Text="EXCEL SAYFASINDAN VERİ ÇEKME / VERİTABANINA İŞLEME";

f2.Activate();

 

}

 

private void button4_Click(object sender, System.EventArgs e)

{

dt.Clear(); 

adp.Fill(dt.Tables[0]);

dataGrid1.DataSource = dt.Tables[0];

}

 

private void button1_Click(object sender, System.EventArgs e)

{

Excel.Application uygulama = new Excel.Application();

Excel.Workbook kitap=uygulama.Workbooks.Add(true);

Excel.Worksheet sayfa=(Excel.Worksheet) uygulama.ActiveSheet;

uygulama.Visible=true;

int rowIndex=1;

int colIndex=0;

 

foreach(DataColumn col in dt.Tables[0].Columns)

{

colIndex++;

sayfa.Cells[1, colIndex]=col.ColumnName;

}

foreach(DataRow row in dt.Tables[0].Rows)

{

rowIndex++;

colIndex=0;

foreach(DataColumn col in dt.Tables[0].Columns)

{

colIndex++;

sayfa.Cells[rowIndex,colIndex]=

row[col.ColumnName].ToString();

}

}

}

 

private void timer1_Tick(object sender, System.EventArgs e)

{

this.Text = this.Text.Substring(1) 

+ this.Text.Substring(0,1);

}

 

private void dataGrid1_Navigate(object sender, NavigateEventArgs ne)

{

 

}

}

}
  Alıntı ile Cevapla
Alt 08-23-09, 02:12   #4 (permalink)
Member
 
SUST@L1 - ait Kullanıcı Resmi (Avatar)

User ID : 4735
Messages : 20
Threads : 7
Thanks : 0
Rat :
SUST@L1 isimli Üye şimdilik offline konumundadır
CryptoSuite.Org
Standart C# da örnek kodlar

C# İle Matris Çarpımı


Kod:
 

private void button1_Click(object sender, EventArgs e)

{

int[,] matris1 = new int[2, 2];

int[,] matris2 = new int[2, 2];

int j, l, k,i, sonuc = 0, boyut1, boyut2, ilkboyut1, ilkboyut2;

matris1[0, 0] = Convert.ToInt32(textBox1.Text);

matris1[0, 1] = Convert.ToInt32(textBox2.Text);

matris1[1, 0] = Convert.ToInt32(textBox3.Text);

matris1[1, 1] = Convert.ToInt32(textBox4.Text);

 

 

matris2[0, 0] = Convert.ToInt32(textBox5.Text);

matris2[0, 1] = Convert.ToInt32(textBox6.Text);

matris2[1, 0] = Convert.ToInt32(textBox7.Text);

matris2[1, 1] = Convert.ToInt32(textBox8.Text);

ilkboyut1 = matris1.Rank;// ilk matrsin sutun sayisi

ilkboyut2 = matris1.GetLength(0);// satir sayisi

 

boyut1 = matris2.Rank;// ikinci matrsin sutun sayisi

boyut2 = matris2.GetLength(0);// satir sayisi

 

for (i = 0; i <= ilkboyut2 - 1; i++)

{

for (j = 0; j <= ilkboyut1 - 1; j++)

{

for (k = 0; j <= boyut1 - 1; k++)

{

sonuc = sonuc + matris1[i,j] * matris2[j,i];

}

}

}

textBox9.Text = sonuc.ToString();
  Alıntı ile Cevapla
Alt 09-27-09, 23:54   #5 (permalink)
Member
 

User ID : 5222
Messages : 25
Threads : 2
Thanks : 0
Rat :
Mc_TiFO isimli Üye şimdilik offline konumundadır
CryptoSuite.Org
Standart

mail kodları iyi oldu, yapmıştım bi tane, başta normal çalışırken sonra hata vermeye başladı, teşekkürler
  Alıntı ile Cevapla
Cevapla

Bookmarks


Konuyu Toplam 1 Üye okuyor. (0 Kayıtlı üye ve 1 Misafir)
 
Seçenekler
Stil

Yetkileriniz
Konu Acma Yetkiniz Yok
Cevap Yazma Yetkiniz Yok
Eklenti Yükleme Yetkiniz Yok
Mesajınızı Değiştirme Yetkiniz Yok

BB code is Açık
Smileler Açık
[IMG] Kodları Açık
HTML-Kodu Kapalı
Trackbacks are Açık
Pingbacks are Açık
Refbacks are Açık



WEZ Format +3. Şuan Saat: 18:51.