一直提示返回的 数据为NULL。
麻烦各位帮我看看这里到底是哪里错了。
感觉上是
下面是全部的代码。
感觉上是
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;
}
}
}
...全文
相关推荐
ajax判断后端返回的数据是否为null的方法
如果满足条件,说明返回的数据有效,可以进行后续处理;如果不满足,说明数据为空,可以进行相应的错误提示或其他处理。
js判断输入字符串是否为空、空格、null的方法总结
; return false; } else { alert(i.value); return true; }}</script>```在上述代码中,如果输入值为"null"字符串,会弹出提示,并且返回
Mybatis返回int或者Integer类型报错的解决办法
由于基本类型不能为`null`,因此会出现`BindingException`,提示尝试从一个方法返回`null`到一个原始类型的返回类型(`int`)。
数据库为空时,文本框不显示null
因此,在读取数据库中的数据并显示到前端页面时,通常需要对NULL值进行适当处理,使其不显示出来或替换为其他更友好的提示信息。
request.getParameter()取值为null的解决方法
然而,在实际应用中,开发者有时会遇到`request.getParameter()`取值返回null的情况,这往往导致了数据无法正确接收,进而影响程序的执行。


