using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class LogWindow : Form
{
SqlConnection conn = new SqlConnection("Data Source=localhost;Initial Catalog=Test; Integrated Security=SSPI;");
SqlCommand statment = new SqlCommand();
SqlDataReader rs;
public LogWindow()
{
InitializeComponent();
statment.Connection = conn;
}
private void polaczButton_Click(object sender, EventArgs e)
{
conn.Open();
statment.CommandText = "select * from Osoby";
rs = statment.ExecuteReader();
if (rs.HasRows)
{
while (rs.Read())
{
dataGridView1.Rows.Add(rs[0], rs[1], rs[2], rs[3]);
}
}
conn.Close();
}
private void button1_Click(object sender, EventArgs e)
{
conn.Open();
statment.CommandText = "INSERT INTO Osoby(Id, Imie ,Nazwisko,Wzrost) VALUES ("
+ idText.Text + ",'"
+ imieText.Text + "', '"
+ nazwiskoText.Text + "', "
+ wzrostText.Text + ")";
statment.ExecuteNonQuery();
MessageBox.Show("record add");
conn.Close();
}
}
}
|