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 WindowsFormsApplication4
{
public partial class Form1 : Form
{
SqlConnection clientConnection;
string connString;
public Form1()
{
InitializeComponent();
connString = "Data Source=ASPEE56\\SQLEXPRESS;Initial Catalog=Test;Integrated Security=True";
clientConnection = new SqlConnection();
clientConnection.ConnectionString = connString;
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == string.Empty || textBox3.Text == string.Empty || textBox4.Text == string.Empty || textBox5.Text == string.Empty || textBox6.Text == string.Empty || textBox7.Text == string.Empty || textBox8.Text == string.Empty || textBox9.Text == string.Empty)
{
MessageBox.Show("Please Insert Data.", "Critical Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign, true);
}
SqlCommand insertCommand = new SqlCommand();
insertCommand.Connection = clientConnection;
insertCommand.CommandText = "insert into GeneralInfo(Nameofcultivator,Sex,Age,Education,Village,tehsil,District,Sizeofholding,Mainoccupation)values(@farmer,@sex,@age,@edu,@vill,@teh,@district,@size,@occupation)";
insertCommand.Parameters.Add("@name", SqlDbType.VarChar, 100).Value = textBox1.Text;
insertCommand.Parameters.Add("@sex", SqlDbType.VarChar, 20).Value = comboBox1.SelectedItem;
insertCommand.Parameters.Add("@age", SqlDbType.Int).Value = textBox3.Text;
insertCommand.Parameters.Add("@edu", SqlDbType.VarChar, 30).Value = textBox4.Text;
insertCommand.Parameters.Add("@vill", SqlDbType.VarChar, 50).Value = textBox5.Text;
insertCommand.Parameters.Add("@teh", SqlDbType.VarChar, 50).Value = textBox6.Text;
insertCommand.Parameters.Add("@district", SqlDbType.VarChar, 50).Value = textBox7.Text;
insertCommand.Parameters.Add("@size", SqlDbType.Int).Value = textBox8.Text;
insertCommand.Parameters.Add("@occupation", SqlDbType.VarChar, 100).Value = textBox9.Text;
if (comboBox1.SelectedItem == null)
{
MessageBox.Show("Please Fill Sex");
}
else
{
insertCommand.Connection.Open();
insertCommand.ExecuteNonQuery();
insertCommand.Connection.Close();
MessageBox.Show("Data Inserted Successfully");
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
}
private void textBox9_TextChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label10_Click(object sender, EventArgs e)
{
}
}
}
kartik_2 0 Newbie Poster
Eternal Newbie 30 Newbie Poster
GeekPlease 16 Junior Poster
Reverend Jim 4,968 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.