Dopiero od niedawna siedzę w c# i jeszcze nie rozumiem dokładnie o co chodzi np. 'posklejane zapytanie' może po prostu wrzucę kod jaki do tej pory napisałem:
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;
using System.Data.OleDb;
namespace SklepMuzyczny
{
public partial class Form1 : Form
{
private string _path;
public Form1()
{
InitializeComponent();
_path = @"SklepMuzyczny.mdb";
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'sklepMuzycznyDataSet.Zamówienia' table. You can move, or remove it, as needed.
this.zamówieniaTableAdapter.Fill(this.sklepMuzycznyDataSet.Zamówienia);
// TODO: This line of code loads data into the 'sklepMuzycznyDataSet.Sprzęt_Muzyczny' table. You can move, or remove it, as needed.
this.sprzęt_MuzycznyTableAdapter.Fill(this.sklepMuzycznyDataSet.Sprzęt_Muzyczny);
// TODO: This line of code loads data into the 'sklepMuzycznyDataSet.Klient' table. You can move, or remove it, as needed.
this.klientTableAdapter.Fill(this.sklepMuzycznyDataSet.Klient);
}
private void gridAuta_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
textBoxId_Klient.Text = gridKlient.Rows[gridKlient.CurrentCell.RowIndex].Cells[0].Value.ToString();
textBoxImie.Text = gridKlient.Rows[gridKlient.CurrentCell.RowIndex].Cells[1].Value.ToString();
textBoxNazwisko.Text = gridKlient.Rows[gridKlient.CurrentCell.RowIndex].Cells[2].Value.ToString();
textBoxUlica.Text = gridKlient.Rows[gridKlient.CurrentCell.RowIndex].Cells[3].Value.ToString();
textBoxNrDomu.Text = gridKlient.Rows[gridKlient.CurrentCell.RowIndex].Cells[4].Value.ToString();
textBoxMiasto.Text = gridKlient.Rows[gridKlient.CurrentCell.RowIndex].Cells[5].Value.ToString();
textBoxTelefon.Text = gridKlient.Rows[gridKlient.CurrentCell.RowIndex].Cells[6].Value.ToString();
}
private void buttonDodajKlient_Click(object sender, EventArgs e)
{
string łańcuchPołączenia = @"Provider=Microsoft.JET.OLEDB.4.0;data source=" + _path;
OleDbConnection łączeOle = new OleDbConnection(łańcuchPołączenia);
łączeOle.Open();
DodanieKlienta(łączeOle);
OdświeżenieZawartościGridu(łączeOle);
łączeOle.Close();
}
private void DodanieKlienta(OleDbConnection łączeOle)
{
DataTable dopisywanyZestawDanych = new DataTable(); // tu można użyć DataSet
string kwerenda = null;
kwerenda = string.Format("INSERT INTO Klient (Id_Klient, Imię, Nazwisko, Ulica, Nr Domu, Miasto, Telefon) VALUES ({0},'{1}','{2}','{3}',{4},'{5}',{6});", textBoxId_Klient.Text, textBoxImie.Text, textBoxNazwisko.Text, textBoxUlica.Text, textBoxNrDomu.Text, textBoxMiasto.Text, textBoxTelefon.Text);
OleDbDataAdapter pośrednikOle = new OleDbDataAdapter(kwerenda, łączeOle);
pośrednikOle.Fill(dopisywanyZestawDanych);
}
private void OdświeżenieZawartościGridu(OleDbConnection łączeOle)
{
DataTable noweDaneTabeli = new DataTable(); // tu NIE można użyć DataSet
string kwerenda = "SELECT * Klient";
OleDbDataAdapter pośrednikOle = new OleDbDataAdapter(kwerenda, łączeOle);
pośrednikOle.Fill(noweDaneTabeli);
gridKlient.DataSource = noweDaneTabeli;
}
}
}