using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Data.SqlClient;
namespace WpfApplication_Demo
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
try
{
if (txt1.Text == "")
{
MessageBox.Show("please enter name");
txt1.Focus();
return;
}
else if (txt2.Text == "")
{
MessageBox.Show("please city name");
txt2.Focus();
return;
}
else if (txt3.Text == "")
{
MessageBox.Show("please money name");
txt3.Focus();
return;
}
else
{
string constr = "Data Source=localhost;Initial Catalog=TestDemo;User Id=sa;Password=passwd@123;";
string query = "";
query = "insert into tbl_demo values('" + txt1.Text + "','" + txt2.Text + "','" + txt3.Text + "')";
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Record Inserted Successfully");
txt1.Text = "";
txt2.Text = "";
txt3.Text = "";
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}