Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

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 CarShowRoom
{
public partial class regCar : Form
{
public regCar()
{
InitializeComponent();
}

private void regCar_Load(object sender, EventArgs e)


{

private void btnSave_Click(object sender, EventArgs e)


{
string ConnectionString = "";
string sql = "";

if (txtId.Text == "")
{
MessageBox.Show("This Field Cann't be Empty");
return;
}

ConnectionString = "Data Source=DESKTOP-4871V66\\SQLEXPRESS;Initial


Catalog=carShowRoom;Integrated Security = true";
SqlConnection con = new SqlConnection(ConnectionString);

sql = "inset into


tblCarShowRoom(carId,carName,model,bodyType,mYear,carCost,chassisNo,engineNo,condit
ion,color) values('" + txtId.Text + "','" + txtName.Text + "','" + txtModel.Text +
"','" + txtBodyType.Text + "','" + txtMYear.Text + "','" + txtCost.Text + "','" +
txtChassisNo.Text + "','" + txtEngineNo.Text + "','" + txtCondition.Text + "','" +
txtColor.Text + "')";

try
{
con.Open();

SqlCommand cmd = new SqlCommand(sql, con);


cmd.ExecuteNonQuery();
MessageBox.Show("Data has been succesfully saved...");

}
catch (Exception ex)
{
MessageBox.Show("error while inseting your data" + ex.ToString());

}
finally
{
con.Close();
}
}

}
}

You might also like