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. ");
}
}
}
专家您好,我创建一个使用C#的Windows窗体应用程序,我想 数据插入到数据库中,但我得到的值的误差和列不匹配,即使我正在为正确的属性输入正确的值。C#.NET的WinForms数据插入错误
我有8个属性(ID与自动增量),并为剩余的7列我输入7个值,但我得到错误值不匹配。
请帮我解决这个问题。我重视
错误我得到的是这里显示的代码和问题截图:
数据库模式截图在这里
请让我知道如果你的问题还没有解决 – Plycoder
可能重复的[sql server:列名或提供的值数量不匹配表定义](http://stackoverflow.com/questions/20372361/sql- server-column-name-or-number-of-supplied-values-does-not-match-table-defini) – Shell
[SQL注入警报](http://msdn.microsoft.com/zh-cn/library/ms161953 %28v = sql.105%29.aspx) - 你应该不**连接你的SQL语句 - 使用**参数化查询**来代替以避免SQL注入 –