comboBox如何从选中的数据中删除数据
时间:2011-12-14
来源:互联网
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 SuperMaket
{
public partial class GoodsTypeForm : Form
{
public GoodsTypeForm()
{
InitializeComponent();
}
//添加数据
private void btnAddGoodsType_Click(object sender, EventArgs e)
{
int index = 0;
if (txtType.Text.Trim() != "")
{
try
{
string sql1 = string.Format("select count(*) from CommoditySort where SortName='{0}'", txtType.Text.Trim());
DBHelp.connection.Open();
SqlCommand comm = new SqlCommand(sql1, DBHelp.connection);
index = (int)comm.ExecuteScalar();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "查询");
}
finally
{
DBHelp.connection.Close();
try
{
if (index >= 1)
{
MessageBox.Show("你输入的商品类别已存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
string sql = string.Format("insert into CommoditySort(SortName) values('{0}')", txtType.Text);
DBHelp.connection.Open();
SqlCommand command = new SqlCommand(sql, DBHelp.connection);
int number = command.ExecuteNonQuery();
if (number < 1)
{
MessageBox.Show("添加商品类别失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("添加商品类别成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "插入商品项出错");
}
finally
{
DBHelp.connection.Close();
}
txtType.Text = "";
cboType.Items.Clear();
InputInit();
}
}
else
{
MessageBox.Show("请输入要添加的商品类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
//数据加载
public void InputInit()
{
try
{
string sql = "select * from CommoditySort";
SqlCommand command = new SqlCommand(sql, DBHelp.connection);
DBHelp.connection.Open();
SqlDataReader reder = command.ExecuteReader();
string sortname = "";
while (reder.Read())
{
sortname = (string)reder[1];
cboType.Items.Add(sortname);
}
reder.Close();
}
finally
{
DBHelp.connection.Close();
}
}
private void GoodsTypeForm_Load(object sender, EventArgs e)
{
InputInit();
}
//删除
private void btnGoodsDel_Click(object sender, EventArgs e)
{
//删除代码如何写
}
}
}
作者: gt0212 发布时间: 2011-12-14
...咋有花括号的聂.
作者: WallesCai 发布时间: 2011-12-14
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28