E-fatura Statu Değiştirici v2 Excelden Toplu Almalı

Categories C#, Nebim-V3Posted on

c:\aktarim\fatura.xls yolundan listeyi data gridwiev içine alır ve veritabanında status değerlerini update eder.

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.Data.SqlClient;

namespace DXApplication5
{

public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
SqlConnection baglanti = new SqlConnection("Data Source=SUNUCUIPSI;Initial Catalog = VTADI; Persist Security Info=True;User ID = sa; Password=ŞİFRE");

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
System.Data.OleDb.OleDbConnection MyConnection;
System.Data.DataSet DtSet;
System.Data.OleDb.OleDbDataAdapter MyCommand;
MyConnection = new System.Data.OleDb.OleDbConnection(@"provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\aktarim\fatura.xls';Extended Properties=Excel 8.0;");
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sayfa1$]", MyConnection);
MyCommand.TableMappings.Add("Table", "Net-informations.com");
DtSet = new System.Data.DataSet();
MyCommand.Fill(DtSet);
dataGridView1.DataSource = DtSet.Tables[0];
MyConnection.Close();
}

private void button3_Click(object sender, EventArgs e)
{
if (baglanti.State == ConnectionState.Closed)

{

//baglanti.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = baglanti;
// cmd.CommandText = ("Update TrInvoiceheader set EInvoiceStatusCode=0 Where InvoiceNumber='" + textBox1.Text + "'");
cmd.CommandText = ("Update TrInvoiceheader set EInvoiceStatusCode=1 Where InvoiceNumber=@C1");
cmd.Parameters.Add(new SqlParameter("@C1", SqlDbType.VarChar));
// cmd.Parameters.Add(new SqlParameter("@C2", SqlDbType.VarChar));
baglanti.Open();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (!row.IsNewRow)
{
cmd.Parameters["@C1"].Value = row.Cells[0].Value;
// cmd.Parameters["@C2"].Value = row.Cells[1].Value;
cmd.ExecuteNonQuery();
}
}

}

}

private void button2_Click(object sender, EventArgs e)
{
{
if (baglanti.State == ConnectionState.Closed)

{

//baglanti.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = baglanti;
// cmd.CommandText = ("Update TrInvoiceheader set EInvoiceStatusCode=0 Where InvoiceNumber='" + textBox1.Text + "'");
cmd.CommandText = ("Update TrInvoiceheader set EInvoiceStatusCode=0 Where InvoiceNumber=@C1");
cmd.Parameters.Add(new SqlParameter("@C1", SqlDbType.VarChar));
// cmd.Parameters.Add(new SqlParameter("@C2", SqlDbType.VarChar));
baglanti.Open();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (!row.IsNewRow)
{
cmd.Parameters["@C1"].Value = row.Cells[0].Value;
// cmd.Parameters["@C2"].Value = row.Cells[1].Value;
cmd.ExecuteNonQuery();
}
}

}

}
}
}
}

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

This site uses Akismet to reduce spam. Learn how your comment data is processed.