C#连接SQL2000数据库并操作数据库

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
using using using using using using using using
System; System.Collections.Generic; ponentModel; System.Data; System.Drawing; System.Text; System.Windows.Forms; System.Data.SqlClient;
} else { MessageBox.Show("信息重复或者输入了无效数据, 请查对!", "提示"); } this.button1.Focus(); } private void Form_pcChange_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.F2) { this.textBox1.Focus(); }//快捷键F2:获取焦点 if (e.KeyCode == Keys.Escape) { this.button3.PerformClick(); }//快捷键ESC:退出 if (e.KeyCode == Keys.Enter) { this.button1.PerformClick(); } if (e.KeyCode == Keys.F3) { this.button2.PerformClick(); } if (e.KeyCode == Keys.F1) { this.button4.PerformClick(); } } private void button4_Click(object sender, EventArgs e) {
MessageBox.Show("本软件刚刚编制,遇到软件异常时, 请及时通知朱世祥进行调试和完善,谢谢合作!\n 使用方法:生成明 细后,双击列表中需要修改的信息,则界面上部会读取到原始信息和默 认提交信息。\n 对默认的提交信息进行编辑和确认后,执行修改即 可。", "提示"); } } }
return null; } } private void button1_Click(object sender, EventArgs e) { StringBuilder sqlstr = new StringBuilder(); sqlstr.Append("SELECT BAT_NO AS '计划号',MRP_NO_SO AS '订单货品代号',SQ_NO AS '请购单号',A.PRD_NO AS '货品代 号',PRD_NAME AS '货品名称',QTY AS '请购数量',SPC AS '货品规 格',CONVERT(VARCHAR(10),A.EST_DD,120) AS '要求交货日' "); sqlstr.Append("\n FROM TF_SQ A LEFT JOIN PRDT B ON A.PRD_NO=B.PRD_NO WHERE SQ_NO='"+this.textBox1.Text+"' "); ds = this.LinkDB(this.dataGridView1.Text, sqlstr.ToString()); this.dataGridView1.DataSource = ds.Tables[0]; } private void button3_Click(object sender, EventArgs e) { this.Close(); } private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { this.textBox2.Text = this.dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); this.textBox3.Text = this.dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString(); this.textBox5.Text = this.dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString(); this.textBox4.Text = this.dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString(); this.textBox9.Text = this.dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); this.textBox8.Text =
namespace ERP暴力修改器 { public partial class Form_pcChange : Form { public Form_pcChange() { InitializeComponent(); } private DataSet ds = null; private DataSet LinkDB(string database, string sqlobj) { try { string constr = "Data Source = ibmser;Database = db_01; User ID =sa; PWD ="; SqlConnection con = new SqlConnection(constr); con.Open(); string sqlstr = sqlobj; SqlDataAdapter sqldataadapter = new SqlDataAdapter(sqlstr, con); DataSet ds = new DataSet(); sqldataadapter.Fill(ds); con.Close(); return ds; } catch (Exception e) { Console.WriteLine(e.Message);
this.dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString(); this.textBox6.Text = this.dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString(); this.textBox7.Text = this.dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString(); this.textBox10.Text = this.dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString(); this.textBox11.Text = this.dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString(); } private void textBox9_TextChanged(object sender, EventArgs e) { SqlConnection mycon = new SqlConnection("data source=ibmser;database=db_01;uid=sa;pwd=;"); mycon.Open(); SqlCommand mycmd = mycon.CreateCommand(); mandText = "select name,spc from prdt where prd_no='" + this.textBox9.Text + "'"; SqlDataReader myreader = mycmd.ExecuteReader(); while (myreader.Read()) { this.textBox8.Text = myreader["name"].ToString(); this.textBox7.Text = myreader["spc"].ToString(); } myreader.Close(); mycon.Close(); } private vБайду номын сангаасid button2_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBox6.Text) || string.IsNullOrEmpty(textBox8.Text) || string.IsNullOrEmpty(textBox9.Text) ||
string.IsNullOrEmpty(textBox11.Text)) { MessageBox.Show("货品代号、货品名称、采购数 量、新交期,不能为空!", "提示"); return; } SqlConnection myConnection = new SqlConnection("data source=ibmser;database=DB_01;uid=sa;pwd=;"); myConnection.Open(); SqlCommand myCommand = myConnection.CreateCommand(); StringBuilder sqlstr = new StringBuilder(); mandText = "UPDATE TF_SQ SET PRD_NO='" + this.textBox9.Text + "',PRD_NAME='" + this.textBox8.Text + "',QTY='" + this.textBox6.Text + "',EST_DD='" + this.textBox11.Text + "',QTY_PO=(CASE WHEN QTY_PO IS NULL THEN NULL WHEN QTY_PO<'" + this.textBox6.Text + "' THEN QTY_PO ELSE " + this.textBox6.Text + " END) WHERE SQ_NO='" + this.textBox1.Text + "' AND PRD_NO='" + this.textBox2.Text + "' ;" + "UPDATE TF_POS SET PRD_NO='" + this.textBox9.Text + "',PRD_NAME='" + this.textBox8.Text + "',QTY='" + this.textBox6.Text + "',EST_DD='" + this.textBox11.Text + "',QTY_PS=(CASE WHEN QTY_PS IS NULL THEN NULL WHEN QTY_PS<'" + this.textBox6.Text + "' THEN QTY_PS ELSE '" + this.textBox6.Text + "' END) WHERE QT_NO='" + this.textBox1.Text + "' AND PRD_NO='" + this.textBox2.Text + "';" +"UPDATE PRDT SET SPC='" + this.textBox7.Text + "' WHERE PRD_NO='" + this.textBox9.Text + "' "; int ni = myCommand.ExecuteNonQuery(); if (ni > 0) { MessageBox.Show("修改成功", "提示");
相关文档
最新文档