有关C#问题请教
using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace HcitPos.BaseInfo
{
public partial class FrmClassInfoSet : Form
{
public FrmClassInfoSet()
{
InitializeComponent();
}
private void ClearControl()
{
txtClassID.Text = "";
txtClassName.Text = "";
txtClassUnit.Text = "";
txtStoreBaseLine.Text = "0";
txtStoreLimit.Text = "0";
}
private void InsertRecords()
{
string classid = txtClassID.Text;
string classname = txtClassName.Text;
string classunit = txtClassUnit.Text;
int storelimit = int.Parse(txtStoreBaseLine.Text);
int storebaseline = int.Parse(txtStoreLimit.Text);
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=HcitPos;Integrated Security=True");
conn.Open();
string insert = "insert into goodsclass (classid, classname, classunit, storelimit, storebaseline) values ('" + classid + "', '" + classname + "', '" + classunit + "', '" + storelimit + "', '" + storebaseline + "')";
SqlCommand cmd = new SqlCommand(insert, conn);
cmd.ExecuteNonQuery();
MessageBox.Show("操作完成!");
ClearControl();
}
private void btnSave_Click(object sender, EventArgs e)
{
if (action == SysUtility.OperationMethod.Insert)
InsertRecords();
if (action == SysUtility.OperationMethod.Edit)
EditRecords();
}
private void btnCancel_Click(object sender, EventArgs e)
{
Close();
}
private SysUtility.OperationMethod action = SysUtility.OperationMethod.Insert;
public void SetActionMode(SysUtility.OperationMethod method)
{
this.action = method;
if (method == SysUtility.OperationMethod.Insert)
this.Text = "添加商品类别";
else
this.Text = "编辑商品类别";
}
public void InitControl(string classID, string className, string classUnit, string storeLimit, string storeBaseLine)
{
txtClassID.Text = classID;
txtClassName.Text = className;
txtClassUnit.Text = classUnit;
txtStoreLimit.Text = storeLimit;
txtStoreBaseLine.Text = storeBaseLine;
txtClassName.Focus();
}
private void EditRecords()
{
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=HcitPos;Integrated Security=True");
conn.Open();
string update = "update goodsclass set classname = '" + className + "',classunit = '" + classUnit + "', storelimit ='" + storeLimit + "',storebaseline = '" + storeBaseLine + "'where classid='" + classID + "'";
SqlCommand cmd = new SqlCommand(update, conn);
try
{
cmd.ExecuteNonQuery();
}
finally
{
conn.Close();
}
MessageBox.Show("操作完成!");
Close();
}
}
}
运行后提示错误 1 当前上下文中不存在名称 “什么什么的”(字体加粗的那几个词)
怎么解决啊?