Inderjeet Kaur

Inderjeet Kaur

  • NA
  • 24
  • 3.1k

following is my C# to insert data but it do not get inserted. why?

Mar 19 2021 4:09 AM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace sample1
{
public partial class main : Form
{
SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\lovel\Desktop\inder\Assign3\Assign3\DataG3.mdf;Integrated Security=True;Connect Timeout=30");
SqlCommand cmd;
public main()
{
InitializeComponent();
}
private void studLoginButton_Click(object sender, EventArgs e)
{
conn.Open();
cmd = new SqlCommand("INSERT INTO loginTab('" + txtStudUser.Text + "','" + txtStudPass.Text + "')", conn);
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Done");
}
}

Answers (7)