Wednesday, September 7, 2011

insert values to database throw sp with c# coding..

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

        private void button1_Click(object sender, EventArgs e)
        {


            string Phcname = textBox1.Text;
            string Chcname = textBox2.Text;
            string Location = textBox3.Text;
            string Address = textBox4.Text;
            try
            {
                SqlConnection sqlcon = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=ilink;Data Source=.");
                   SqlCommand Cmd = new SqlCommand("Employeedetails", sqlcon);
                    Cmd.CommandType = CommandType.StoredProcedure;
                    Cmd.Parameters.Add("@Phcname", SqlDbType.VarChar).Value = textBox1.Text;
                    Cmd.Parameters.Add("@Chcname", SqlDbType.VarChar).Value = textBox2.Text;
                    Cmd.Parameters.Add("@Location", SqlDbType.VarChar).Value = textBox3.Text;
                    Cmd.Parameters.Add("@Address", SqlDbType.VarChar).Value = textBox4.Text;
                sqlcon.Open();
                int rows = Cmd.ExecuteNonQuery();
                if (rows == 1)
                {
                    MessageBox.Show("created successfully");


                }
                else
                {
                    MessageBox.Show("creation failed");
                }
               //Cmd.ExecuteNonQuery();
                sqlcon.Close();

            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
   

       
public  string Employeedetails { get; set; }}
    }

No comments:

Post a Comment