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 crudwithlogin
{
public partial class student_registration : Form
{
SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Android\Documents\Data.mdf;Integrated Security=True;Connect Timeout=30");
public student_registration()
{
InitializeComponent();
}
private void student_registration_Load(object sender, EventArgs e)
{
label1.Text = "You are logged in as "+((Form)this.MdiParent).Controls["label1"].Text;
}
private void button1_Click(object sender, EventArgs e)
{
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into student values ('"
+ textBox1.Text
+ "','"
+ textBox2.Text
+ "''"
+ dateTimePicker2.Value.ToString()
+ "','"
+ textBox4.Text
+ "','"
+ comboBox2.Text
+ "','"
+ textBox6.Text
+ "','"
+ dateTimePicker1.Value.ToString()
+ "')";
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Data Added Successfully. ");
}
}
}
Hello Experts I am creating a Windows forms app using C#, I am trying to insert data into a database but I am getting an error of values and columns do not match even though I am entering the right value for right attribute.
I have 8 attributes (id with auto increment), and for the remaining 7 columns I am entering 7 values but I get error of value not match.
Please help me solve this problem. I have attached the code and screenshots of problem
Error I get is shown here:
Database schema screenshot is here