form
源码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;
using System.Reflection;
namespace WindowsApplication2
{
public partial class insert : DevExpress.XtraEditors.XtraForm
{
public insert()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String MyConn = "server=localhost.;database=M10;integrated security=SSPI";
SqlConnection MyConnection = new SqlConnection(MyConn);
string MyInsert = "insert into m_task_001(FBillNo,FItemID,FPQty,FStatus)values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')";
SqlCommand MyCommand = new SqlCommand(MyInsert, MyConnection);
try
{
MyConnection.Open();
MyCommand.ExecuteNonQuery();
MyConnection.Close();
textBox1.Text = textBox2.Text = textBox3.Text = textBox4.Text = "";
MessageBox.Show("成功添加信息!");
}
catch (Exception ex)
{
MessageBox.Show("错误信息:" + ex.Message, "出现错误");
}
}
}
}