我无法将数据从 c# 应用程序保存到我的 sql 数据库中,它甚至没有给我任何错误。我是不是错过了什么。它是一个简单的脚本,它将从文本框中获取用户输入并将其插入 SQL 数据库的复选框。这是我的脚本。
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 Kaizen_Tracking_System_V1
{
public partial class Individual : Form
{
SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Asus\Documents\Visual Studio 2010\Projects\Kaizen Tracking System V1\Kaizen Tracking System V1\Database1.mdf;Integrated Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand();
public Individual()
{
InitializeComponent();
}
private void Individual_Load(object sender, EventArgs e)
{
cmd.Connection = cn;
}
private void button1_Click(object sender, EventArgs e)
{
if (logTxtBox.Text != "" & lnameTextBox.Text != "" & fnameTextBox.Text != "" & depCheckBox1.Text != "" & DepCheckBox2.Text != "" & depCheckBox3.Text != "" & depCheckBox4.Text != "" & locationComboBox1.Text != "" & processTextBox.Text != "" & typeTextBox.Text != "" & odgrecdataTextBox.Text != "" & kimpdateTextBox.Text != "" & cipaTextBox.Text != "" & cspmTextBox.Text != "" & rewardgivenTextBox.Text != "" & rcppTextBox.Text != "" & kvdTextBox.Text != "" & ylocationTextBox.Text != "" & detailRichTextBox1.Text != "")
{
cn.Open();
cmd.CommandText = "insert into kaizentracker (lognum,lname,fname,dept,location,process,type,odgrecdate,kimpdate,cipa,cspm,rewardgiven,rcpp,kverifieddate,ylocation,details) values ('" + logTxtBox.Text + "' , '" + lnameTextBox.Text + "' , '" + fnameTextBox.Text + "' , '" + depCheckBox1.Text + "' , '" + DepCheckBox2.Text + "' , '" + depCheckBox3.Text + "' ,'" + depCheckBox4.Text + "' , '" + locationComboBox1.Text + "' , '" + processTextBox.Text + "' , '" + typeTextBox.Text + "' , '" + odgrecdataTextBox.Text + "' , '" + kimpdateTextBox.Text + "' , '" + cipaTextBox.Text + "' , '" + cspmTextBox.Text + "' , '" + rewardgivenTextBox.Text + "' , '" + rcppTextBox.Text + "' , '" + kvdTextBox.Text + "' , '" + ylocationTextBox.Text + "' , '" + detailRichTextBox1.Text + "') ";
cmd.ExecuteNonQuery();
cmd.Clone();
MessageBox.Show("Data Saved");
cn.Close();
logTxtBox.Text = "";
lnameTextBox.Text = "";
fnameTextBox.Text = "";
depCheckBox1.Text = "";
DepCheckBox2.Text = "";
depCheckBox3.Text = "";
depCheckBox4.Text = "";
locationComboBox1.Text = "";
processTextBox.Text = "";
typeTextBox.Text = "";
odgrecdataTextBox.Text = "";
kimpdateTextBox.Text = "";
cipaTextBox.Text = "";
cspmTextBox.Text = "";
rewardgivenTextBox.Text = "";
rcppTextBox.Text = "";
kvdTextBox.Text = "";
ylocationTextBox.Text = "";
detailRichTextBox1.Text = "";
}
}
}
}