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 WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string gender;
if (radioButton1.Checked)
{
gender = radioButton1.Text.ToString();
}
else
{
gender = radioButton2.Text.ToString();
}
SqlConnection cn = new SqlConnection("server=LAB2-86;database=studentsdb;user=sa;password=aptech");
string insert;
insert = "insert into db values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + gender + "')";
SqlCommand sc = new SqlCommand(insert, cn);
cn.Open();
if (MessageBox.Show("Do want to insert record? ", "Winform", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
{
sc.ExecuteNonQuery();
}
string select = "select * from db";
SqlDataAdapter da = new SqlDataAdapter(select, cn);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
cn.Close();
}
}
}
No comments:
Post a Comment