Ivo
Member
- Joined
- Feb 8, 2022
- Messages
- 18
- Programming Experience
- Beginner
C#:
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 CRUD
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnInsert_Click(object sender, EventArgs e)
{
string query = "INSERT INTO Employee(Employeeid,EmployeeName,EmployeeContact,EmployeeGender,EmployeeBirthDate)" +
" VALUES(@name,@contact,@gender,@birthDate)";
SqlConnection con = new SqlConnection("Data Source=.\sqlexpress;Initial Catalog=samplesdb;Integrated Security=True");
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.AddWithValue("@name", txtName.Text);
cmd.Parameters.AddWithValue("@contact", txtContact.Text);
cmd.Parameters.AddWithValue("@gender", cmbGender.Text);
cmd.Parameters.AddWithValue("@birthdate", dtBirthDate.Value);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Workflow correct added to the database");
}
}
}