📄 produceform.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Elysian
{
public partial class produceForm : Form
{
SqlConnection sqlconn;
SqlDataAdapter adapter;
DataSet ds = new DataSet();
public produceForm()
{
InitializeComponent();
}
private void produceForm_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“elysianDBDataSet2.商品基本信息”中。您可以根据需要移动或移除它。
this.商品基本信息TableAdapter1.Fill(this.elysianDBDataSet2.商品基本信息);
}
private string GetConnectionString()
{
return "data source=.;initial catalog=ElysianDB;integrated security=true";
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void 查询ToolStripMenuItem_Click(object sender, EventArgs e)
{
string selectStr = string.Empty;
selectStr = "select * from 商品基本信息_view";
if (textBox1.Text != "")
{
selectStr = selectStr + " " + "where 商品编号" + " " + comboBox1.Text + " " + "'" + textBox1.Text + "'";
if (textBox2.Text != "")
{
selectStr = selectStr + " " + "and 商品名称" + " " + comboBox1.Text + " " + "'" + textBox2.Text + "'";
}
}
else
{
if (textBox2.Text != "")
{
selectStr = selectStr + " " + "where 商品名称" + " " + comboBox1.Text + " " + "'" + textBox2.Text + "'";
}
MessageBox.Show("请您输入要查询的信息");
}
sqlconn = new SqlConnection(GetConnectionString());
SqlCommand sqlcomm = new SqlCommand();
sqlcomm.CommandText = selectStr;
sqlcomm.Connection = sqlconn;
try
{
sqlconn.Open();
}
catch (SqlException ex)
{
MessageBox.Show("连接数据库出错"+ex.ToString(),"提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);
}
ds.Clear();
adapter = new SqlDataAdapter(sqlcomm);
adapter.Fill(ds, "商品基本信息");
dataGridView2.DataSource = ds.Tables[0];
sqlconn.Close();
textBox1.Text = "";
textBox2.Text = "";
}
private void button2_Click(object sender, EventArgs e)
{
string selectStr = string.Empty;
selectStr = "select * from 商品基本信息_view";
if (textBox1.Text.ToString().Trim() != "")
{
selectStr = selectStr + " " + "where 商品编号" + " " + comboBox1.Text + " " + "'" + textBox1.Text + "'";
if (textBox2.Text.ToString().Trim() != "")
{
selectStr = selectStr + " " + "and 商品名称" + " " + comboBox1.Text + " " + "'" + textBox2.Text + "'";
}
}
else
{
if (textBox2.Text.ToString().Trim() != "")
{
selectStr = selectStr + " " + "where 商品名称" + " " + comboBox1.Text + " " + "'" + textBox2.Text + "'";
}
MessageBox.Show("请您输入要查询的信息");
}
sqlconn = new SqlConnection(GetConnectionString());
SqlCommand sqlcomm = new SqlCommand();
sqlcomm.CommandText = selectStr;
sqlcomm.Connection = sqlconn;
try
{
sqlconn.Open();
}
catch (SqlException ex)
{
MessageBox.Show("连接数据库出错", ex.ToString(), MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}
ds.Clear();
adapter = new SqlDataAdapter(sqlcomm);
adapter.Fill(ds, "商品基本信息");
dataGridView2.DataSource = ds.Tables[0];
sqlconn.Close();
textBox1.Text = "";
textBox2.Text = "";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -