i want to modify my code to display inserted data in data gridview...
My code is
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 employee
{
public partial class details : Form
{
public details()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string empid = textBox1.Text;
string name = textBox2.Text;
string designation = textBox3.Text;
string salary = textBox6.Text;
string value = "";
bool isChecked = radioButton1.Checked;
if (isChecked)
value = radioButton1.Text;
else
value = radioButton2.Text;
string address = textBox4.Text;
string pincode = textBox5.Text;
string prifix = textBox8.Text;
string phone = textBox7.Text;
string email = textBox9.Text;
if (empid == "" || name == "" || designation == "" || salary == "" || address == "" || pincode == "" || prifix == "" || phone == "" || email == "")
{
MessageBox.Show("Please ensure all fields are entered", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
System.Data.SqlClient.SqlConnection sqlcommand1 = new System.Data.SqlClient.SqlConnection("Persist Security Info=True;User ID=*******;Password=******;Initial Catalog=ubsemp;Server=****");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "IF NOT EXISTS(SELECT * FROM UEMPLOYEE WHERE EMPLOYEE_ID=@EMPLOYEE_ID) INSERT INTO UEMPLOYEE(EMPLOYEE_ID,NAME,DESIGNATTION,GENDER,ADDRESS,PINCODE,SALARY,PHPREFIX,PHONE,EMAIL) VALUES(@EMPLOYEE_ID,@NAME,@DESIGNATTION,@GENDER,@ADDRESS,@PINCODE,@SALARY,@PHPREFIX,@PHONE,@EMAIL)";
cmd.Parameters.AddWithValue("@EMPLOYEE_ID", empid);
cmd.Parameters.AddWithValue("@NAME", name);
cmd.Parameters.AddWithValue("@DESIGNATTION", designation);
cmd.Parameters.AddWithValue("@SALARY", salary);
cmd.Parameters.AddWithValue("GENDER", value);
cmd.Parameters.AddWithValue("@ADDRESS", address);
cmd.Parameters.AddWithValue("PINCODE", pincode);
cmd.Parameters.AddWithValue("PHPREFIX", prifix);
cmd.Parameters.AddWithValue("PHONE", phone);
cmd.Parameters.AddWithValue("@EMAIL", email);
cmd.Connection = sqlcommand1;
sqlcommand1.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("successfully inserted");
}
}
}
}