代码如下~~~~~求帮助啊!!!
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;
using System.Configuration;namespace drugstore.Inventory
{
public partial class Pricing : Form
{
static string connStr = System.Configuration.ConfigurationManager.ConnectionStrings[1].ToString();
SqlConnection myConn = new SqlConnection(connStr);
SqlCommand myCmd = new SqlCommand();
SqlDataAdapter myDA = new SqlDataAdapter();
DataTable dtAllProduct = new DataTable(); public Pricing()
{
InitializeComponent();
} private void Pricing_Load(object sender, EventArgs e)
{
myCmd.CommandText = "select drugId,d_name,SalesPrice,purchasePrice,d_unit from t_drugsupervise";
myCmd.Connection = myConn;
myDA.SelectCommand = myCmd;
myDA.Fill(dtAllProduct);
dataGridView1.DataSource = dtAllProduct;
} private void button1_Click(object sender, EventArgs e)
{
string Id = txtId.Text;
string inprice = txtInPrice.Text;
string serprice = txtSerPrice.Text;
string drugUnit = DrugUnit.Text;
SqlConnection myConn = new SqlConnection(connStr);
SqlCommand myCmd = new SqlCommand(string.Format("UPDATE t_drugsupervise SET SalesPrice = '{0}',purchasePrice = '{1}',d_unit = '{2}' WHERE drugId = '{3}'", serprice, inprice, drugUnit, Id), myConn);
int rows = myCmd.ExecuteNonQuery();
myConn.Open();
if (rows > 0)
{
MessageBox.Show("修改成功!");
this.Close();
}
else
{
MessageBox.Show("修改失败!");
}
myConn.Close();
} private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
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;
using System.Configuration;namespace drugstore.Inventory
{
public partial class Pricing : Form
{
static string connStr = System.Configuration.ConfigurationManager.ConnectionStrings[1].ToString();
SqlConnection myConn = new SqlConnection(connStr);
SqlCommand myCmd = new SqlCommand();
SqlDataAdapter myDA = new SqlDataAdapter();
DataTable dtAllProduct = new DataTable(); public Pricing()
{
InitializeComponent();
} private void Pricing_Load(object sender, EventArgs e)
{
myCmd.CommandText = "select drugId,d_name,SalesPrice,purchasePrice,d_unit from t_drugsupervise";
myCmd.Connection = myConn;
myDA.SelectCommand = myCmd;
myDA.Fill(dtAllProduct);
dataGridView1.DataSource = dtAllProduct;
} private void button1_Click(object sender, EventArgs e)
{
string Id = txtId.Text;
string inprice = txtInPrice.Text;
string serprice = txtSerPrice.Text;
string drugUnit = DrugUnit.Text;
SqlConnection myConn = new SqlConnection(connStr);
SqlCommand myCmd = new SqlCommand(string.Format("UPDATE t_drugsupervise SET SalesPrice = '{0}',purchasePrice = '{1}',d_unit = '{2}' WHERE drugId = '{3}'", serprice, inprice, drugUnit, Id), myConn);
int rows = myCmd.ExecuteNonQuery();
myConn.Open();
if (rows > 0)
{
MessageBox.Show("修改成功!");
this.Close();
}
else
{
MessageBox.Show("修改失败!");
}
myConn.Close();
} private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
int rows = myCmd.ExecuteNonQuery();
这里try一下