110,535
社区成员
发帖
与我相关
我的任务
分享
string strsql = string.Format("select(CommodityName='{0}',SortID='{1}',CommodityPrice='{2}',IsDiscount='{3}',ReducedPrice='{4}')from commodity", txtName.Text, txtType.SelectedValue.ToString(), nudPrice.Value, IsDiscount, numericUpDown1.Value);
这句错了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 SuperMarket
{
public partial class CommoDityUpdate : Form
{
public int CommodityID;
public string CommodityName;
public string SortName;
public decimal CommodityPrice;
public bool IsDiscount;
public decimal ReducedPrice;
DataSet ds;
SqlConnection conn = new SqlConnection("server=.;database=SuperMarket;uid=sa;pwd=Shaona520;");
public CommoDityUpdate()
{
InitializeComponent();
}
private void CommoDityUpdate_Load(object sender, EventArgs e)
{
ds = new DataSet();
string strsql = "select SortName,SortID from CommoditySort";
SqlDataAdapter adapter = new SqlDataAdapter(strsql, conn);
adapter.Fill(ds, "CommoditySort");
txtType.DataSource = ds.Tables["CommoditySort"];
txtType.DisplayMember = "SortName";
txtType.ValueMember = "SortID";
txtType.SelectedIndex = 0;
}
private void nudPrice_ValueChanged(object sender, EventArgs e)
{
if (chkSole.Checked == false)
{
numericUpDown1.Enabled = false;
numericUpDown1.Value = nudPrice.Value;
}
else
{ numericUpDown1.Enabled = true; }
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
if (checkUserInput())
{
if (checkedUserInfotoSql())
{
UpdateUser();
}
else
{ MessageBox.Show("您的信息和数据库信息不一致;"); }
}
}
private bool checkedUserInfotoSql()
{
if (checkUserDATA())
{
if (nudPrice.Value != 0)
{
return true;
}
}
return false;
}
private bool checkUserDATA()
{
try
{
conn.Open();
string strsql = string.Format("select(CommodityName='{0}',SortID='{1}',CommodityPrice='{2}',IsDiscount='{3}',ReducedPrice='{4}')from commodity", txtName.Text, txtType.SelectedValue.ToString(), nudPrice.Value, IsDiscount, numericUpDown1.Value);
SqlCommand cmd = new SqlCommand(strsql, conn);
int count = cmd.ExecuteNonQuery();
if (count > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception e1)
{
MessageBox.Show(e1.Message);
return false;
}
finally
{
conn.Close();
}
}
private void UpdateUser()
{
int IsDiscount;
if (chkSole.Checked == false)
{
IsDiscount = 0;
}
else
{ IsDiscount = 1; }
try
{
conn.Open();
string strsql = string.Format("Update commodity set(CommodityName,SortID,CommodityPrice,IsDiscount,ReducedPrice)values('{0}','{1}','{2}','{3}','{4}')",txtName.Text, txtType.SelectedValue.ToString(), nudPrice.Value, IsDiscount, numericUpDown1.Value);
SqlCommand cmd = new SqlCommand(strsql, conn);
int count = cmd.ExecuteNonQuery();
if (count > 0)
{
MessageBox.Show("修改成功");
}
else {
MessageBox.Show("修改失败");
}
}
catch (Exception e1) { MessageBox.Show(e1.Message); }
finally {
conn.Close();
}
}
private bool checkUserInput()
{
if (txtName.Text == null)
{
MessageBox.Show("请输入用户名,用户名不允许为空");
txtName.Focus();
return false;
}
else if (nudPrice.Value == 0)
{
MessageBox.Show("对不起预售价格不允许为空");
nudPrice.Focus();
}
return true;
}
}
}
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 SuperMarket
{
public partial class CommoDityUpdate : Form
{
public int CommodityID;
public string CommodityName;
public string SortName;
public decimal CommodityPrice;
public bool IsDiscount;
public decimal ReducedPrice;
DataSet ds;
SqlConnection conn = new SqlConnection("server=.;database=SuperMarket;uid=sa;pwd=Shaona520;");
public CommoDityUpdate()
{
InitializeComponent();
}
private void CommoDityUpdate_Load(object sender, EventArgs e)
{
ds = new DataSet();
string strsql = "select SortName,SortID from CommoditySort";
SqlDataAdapter adapter = new SqlDataAdapter(strsql, conn);
adapter.Fill(ds, "CommoditySort");
txtType.DataSource = ds.Tables["CommoditySort"];
txtType.DisplayMember = "SortName";
txtType.ValueMember = "SortID";
txtType.SelectedIndex = 0;
}
private void nudPrice_ValueChanged(object sender, EventArgs e)
{
if (chkSole.Checked == false)
{
numericUpDown1.Enabled = false;
numericUpDown1.Value = nudPrice.Value;
}
else
{ numericUpDown1.Enabled = true; }
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
if (checkUserInput())
{
if (checkedUserInfotoSql())
{
UpdateUser();
}
else
{ MessageBox.Show("您的信息和数据库信息不一致;"); }
}
}
private bool checkedUserInfotoSql()
{
if (checkUserDATA())
{
if (nudPrice.Value != 0)
{
return true;
}
}
return false;
}
private bool checkUserDATA()
{
try
{
if (txtName.Text == CommodityName && txtType.Text == SortName && nudPrice.Value == CommodityPrice && IsDiscount == chkSole.Checked && numericUpDown1.Value == ReducedPrice)
{
return false;
}
else
{
return true;
}
}
catch (Exception e1)
{
MessageBox.Show(e1.Message);
return false;
}
finally
{
conn.Close();
}
}
private void UpdateUser()
{
int IsDiscount;
if (chkSole.Checked == false)
{
IsDiscount = 0;
}
else
{ IsDiscount = 1; }
try
{
conn.Open();
string strsql = string.Format(@"update Commodity
set CommodityName='{0}',SortID='{1}',CommodityPrice='{2}',IsDiscount='{3}',ReducedPrice='{4}'
where CommodityID='{5}'",txtName.Text, txtType.SelectedValue.ToString(),nudPrice.Value, IsDiscount, numericUpDown1.Value,CommodityID);
SqlCommand cmd = new SqlCommand(strsql, conn);
int count = cmd.ExecuteNonQuery();
if (count > 0)
{
MessageBox.Show("修改成功");
}
else {
MessageBox.Show("修改失败");
}
}
catch (Exception e1) { MessageBox.Show(e1.Message); }
finally {
conn.Close();
}
}
private bool checkUserInput()
{
if (txtName.Text == null)
{
MessageBox.Show("请输入用户名,用户名不允许为空");
txtName.Focus();
return false;
}
else if (nudPrice.Value == 0)
{
MessageBox.Show("对不起预售价格不允许为空");
nudPrice.Focus();
}
return true;
}
}
}
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 SuperMarket
{
public partial class CommoDityUpdate : Form
{
public int CommodityID;
public string CommodityName;
public string SortName;
public decimal CommodityPrice;
public bool IsDiscount;
public decimal ReducedPrice;
DataSet ds;
SqlConnection conn = new SqlConnection("server=.;database=SuperMarket;uid=sa;pwd=Shaona520;");
public CommoDityUpdate()
{
InitializeComponent();
}
private void CommoDityUpdate_Load(object sender, EventArgs e)
{
ds = new DataSet();
string strsql = "select SortName,SortID from CommoditySort";
SqlDataAdapter adapter = new SqlDataAdapter(strsql, conn);
adapter.Fill(ds, "CommoditySort");
txtType.DataSource = ds.Tables["CommoditySort"];
txtType.DisplayMember = "SortName";
txtType.ValueMember = "SortID";
txtType.SelectedIndex = 0;
}
private void nudPrice_ValueChanged(object sender, EventArgs e)
{
if (chkSole.Checked == false)
{
numericUpDown1.Enabled = false;
numericUpDown1.Value = nudPrice.Value;
}
else
{ numericUpDown1.Enabled = true; }
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
if (checkUserInput())
{
if (checkedUserInfotoSql())
{
UpdateUser();
}
else
{ MessageBox.Show("您的信息和数据库信息不一致;"); }
}
}
private bool checkedUserInfotoSql()
{
if (checkUserDATA())
{
if (nudPrice.Value != 0)
{
return true;
}
}
return false;
}
private bool checkUserDATA()
{
try
{
if (txtName.Text == CommodityName && txtType.Text == SortName && nudPrice.Value == CommodityPrice && IsDiscount == chkSole.Checked && numericUpDown1.Value == ReducedPrice)
{
return false;
}
else
{
return true;
}
}
catch (Exception e1)
{
MessageBox.Show(e1.Message);
return false;
}
finally
{
conn.Close();
}
}
private void UpdateUser()
{
int IsDiscount;
if (chkSole.Checked == false)
{
IsDiscount = 0;
}
else
{ IsDiscount = 1; }
try
{
conn.Open();
string strsql = string.Format("Update commodity set CommodityName,SortID,CommodityPrice,IsDiscount,ReducedPrice values('{0}','{1}','{2}','{3}','{4}')",txtName.Text, txtType.SelectedValue.ToString(), nudPrice.Value, IsDiscount, numericUpDown1.Value);
SqlCommand cmd = new SqlCommand(strsql, conn);
int count = cmd.ExecuteNonQuery();
if (count > 0)
{
MessageBox.Show("修改成功");
}
else {
MessageBox.Show("修改失败");
}
}
catch (Exception e1) { MessageBox.Show(e1.Message); }
finally {
conn.Close();
}
}
private bool checkUserInput()
{
if (txtName.Text == null)
{
MessageBox.Show("请输入用户名,用户名不允许为空");
txtName.Focus();
return false;
}
else if (nudPrice.Value == 0)
{
MessageBox.Show("对不起预售价格不允许为空");
nudPrice.Focus();
}
return true;
}
}
}
String.Format("select * from tb where CommodityName='{0}',SortID='{1}',CommodityPrice='{2}',IsDiscount='{3}',ReducedPrice='{4}'",txtName.Text, txtType.SelectedValue.ToString(), nudPrice.Value, IsDiscount, numericUpDown1.Value)