i was just doing a simple thing in C#, just trying to put the values feeded in the text boxes in sql database. i am giving the code below the code executed perfectly but when i went to look into the table data there was no data inserted...... pls HELP...!!!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.Sql;
namespace txtbox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection cn=new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Details.mdf;Integrated Security=True;User Instance=True");
string sql = " INSERT into employee(fname, mname, lname) VALUES (@fname, @mname,@lname)";
SqlCommand cmd = new SqlCommand(sql, cn);
cmd.Parameters.Add(new SqlParameter("@fname", SqlDbType.NVarChar,50));
cmd.Parameters.Add(new SqlParameter("@mname", SqlDbType.NVarChar,50));
cmd.Parameters.Add(new SqlParameter("@lname", SqlDbType.NVarChar,50));
cmd.Parameters[0].Value = textBox1.Text;
cmd.Parameters[1].Value = textBox2.Text;
cmd.Parameters[2].Value = textBox3.Text;
cn.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("inserted successfully");
}
}
}
at the end i get the message in the message box "inserted successfully" but there is no value inserted in the table....