C#.Net Insert Update Delete Advance
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
using
System.Windows.Forms;
using
System.Data.SqlClient;
namespace
WindowsFormsApplication2
{
public partial class Form2 : Form
{
public
Form2()
{
InitializeComponent();
}
private void
Insert_Click(object sender, EventArgs e)
{
SqlConnection con
= new SqlConnection("Data Source=ICTV34;Initial
Catalog=ICTPT21;Integrated Security=True");
con.Open();
SqlCommand cmd
= new SqlCommand("INSERT INTO student VALUES
('"+textBox1.Text+"',@fname,@lname,@fullname,@gender,@dob,@course,@mobile,@regtime)",
con);
//cmd.Parameters.AddWithValue("@stuid",
textBox1.Text);
cmd.Parameters.AddWithValue("@fname",
textBox2.Text);
cmd.Parameters.AddWithValue("@lname",
textBox3.Text);
cmd.Parameters.AddWithValue("@fullname",
textBox2.Text+" "+textBox3.Text);
if(radioButton1.Checked)
{
cmd.Parameters.AddWithValue("@gender", "Male");
}
else
{
cmd.Parameters.AddWithValue("@gender", "Female");
}
cmd.Parameters.AddWithValue("@dob",dateTimePicker1.Text);
cmd.Parameters.AddWithValue("@course",
comboBox1.Text);
cmd.Parameters.AddWithValue("@mobile",
textBox4.Text);
cmd.Parameters.AddWithValue("@regtime",DateTime.Now.ToString());
cmd.ExecuteNonQuery();
MessageBox.Show("Done");
}
private void
timer1_Tick(object sender, EventArgs e)
{
label9.Text = DateTime.Now.ToString("dd-MMM-yyyy
hh:mm:ss tt");
}
}
}
0 Comments