private void btnAdd_Click(object sender, EventArgs e)
{
//string select1="insert into tb_user values ( } private void btnEdit_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || cboxUName.Text == "" || txtUPwd.Text == "" || cboxURight.Text == "" )
MessageBox.Show("请输入相应的值!"); string select2 = "update tb_User set UserName= '" + cboxUName.Text + "', StorePeople='" + txtUPwd.Text + "', StorePhone='" + cboxURight.Text + "', StoreUnit=' ";
comm = new SqlCommand(select2, conn);
conn.Open();
comm.ExecuteNonQuery();
ds = new DataSet();
da.Fill(ds);
this.dgvUInfo.DataSource = ds.Tables[0];
MessageBox.Show("命令执行成功!");
return;
} private void btnDel_Click(object sender, EventArgs e)
{
int a = 0;
try { a = int.Parse(textBox1.Text); }
catch (Exception ee) { MessageBox.Show(ee.Message); return; }
string delete = "delete from tb_User where UserID= " + textBox1.Text + " ";
comm = new SqlCommand(delete, conn);
conn.Open();
comm.ExecuteNonQuery();
ds = new DataSet();
da.Fill(ds);
this.dgvUInfo.DataSource = ds.Tables[0];
conn.Close();
{
//string select1="insert into tb_user values ( } private void btnEdit_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || cboxUName.Text == "" || txtUPwd.Text == "" || cboxURight.Text == "" )
MessageBox.Show("请输入相应的值!"); string select2 = "update tb_User set UserName= '" + cboxUName.Text + "', StorePeople='" + txtUPwd.Text + "', StorePhone='" + cboxURight.Text + "', StoreUnit=' ";
comm = new SqlCommand(select2, conn);
conn.Open();
comm.ExecuteNonQuery();
ds = new DataSet();
da.Fill(ds);
this.dgvUInfo.DataSource = ds.Tables[0];
MessageBox.Show("命令执行成功!");
return;
} private void btnDel_Click(object sender, EventArgs e)
{
int a = 0;
try { a = int.Parse(textBox1.Text); }
catch (Exception ee) { MessageBox.Show(ee.Message); return; }
string delete = "delete from tb_User where UserID= " + textBox1.Text + " ";
comm = new SqlCommand(delete, conn);
conn.Open();
comm.ExecuteNonQuery();
ds = new DataSet();
da.Fill(ds);
this.dgvUInfo.DataSource = ds.Tables[0];
conn.Close();
解决方案 »
- C#调用ActiveX控件的参数传递问题byte[]与ref byte
- VS2010谁出现过这种问题??
- 自定义了个控件,能不把其中的某一个控件不显示到工具栏中
- 如何判断何时自动换行
- 怎样能根据当前日期返回数据
- 从多个文件中获取数据
- 如何在应用程序调用WebService时对该WebService进行调试阿?这两个工程在同一个solution下面
- 看看问题出在哪?
- 请教高手,关于win服务的安装,急求..........
- 高分求C#输出问题!(任意分值,谢谢!)
- C#中怎样使的向comboBox中输入的内容自动的保存到下拉列表框里?
- C#读取xml文件,意外的 XML 声明。XML 声明必须是文档中的第一个节点并且在它之前不允许出现空白字符。 第 2 行,位置 3。
//這是例子,插入語句,插入前查詢數據庫有無數據,有就更新,沒有則插入
//string delSql = "delete from table where 條件";
//我這個是oracle數據庫的 sql的就把oraclecommand改成相應的sqlcommand就好
string insertSql = "DECLARE num NUMBER;BEGIN SELECT COUNT (*) INTO num FROM glb_rpt_board WHERE start_time = '" + stime + "';IF num <> 0 THEN UPDATE glb_rpt_board SET business = '" + textBoxBusiness.Text.Trim() + "', model = '" + textBoxLine.Text.Trim() + "', input_step = '" + dt.Rows[i][0] + "', output_step ='" + dt.Rows[i][1] + "',end_time = '" + etime + "',otime = " + Convert.ToDecimal(dt.Rows[i][4]) +
@", input ="+Convert.ToDecimal(dt.Rows[i][5])+@",output = "+Convert.ToDecimal(dt.Rows[i][6])+@",fpy = "+Convert.ToDecimal(dt.Rows[i][7])+@",uph = "+Convert.ToDecimal(dt.Rows[i][8])+@",upph ="+Convert.ToDecimal(dt.Rows[i][9])+@" where start_time = '"+stime+ @"';ELSE INSERT INTO glb_rpt_board VALUES ('" + textBoxBusiness.Text.Trim() + @"', '" + textBoxLine.Text.Trim() + @"', '" + dt.Rows[i][0] +
@"', '" + dt.Rows[i][1] + @"','" + stime + @"','" + etime +@"',"+Convert.ToDecimal(dt.Rows[i][4])+@","+Convert.ToDecimal(dt.Rows[i][5])+@","+Convert.ToDecimal(dt.Rows[i][6])+@","+Convert.ToDecimal(dt.Rows[i][7])+@","+Convert.ToDecimal(dt.Rows[i][8])+@","+Convert.ToDecimal(dt.Rows[i][9])+"); END IF;END;";
OracleCommand insertCmd = conn.CreateCommand();
insertCmd.CommandText = insertSql;
insertCmd.ExecuteNonQuery();
其中的數據庫語句
/* Formatted on 2013/06/13 09:19 (Formatter Plus v4.8.8) */
DECLARE
num NUMBER;
BEGIN
SELECT COUNT (*)
INTO num
FROM glb_rpt_uph
WHERE start_time = TO_DATE ('2013-6-13 15:30:00', 'yyyy-MM-dd hh24:mi:ss'); IF num <> 0
THEN
UPDATE glb_rpt_uph
SET model = 'AK73-BTE-EA1',
shift = 'd',
end_time =
TO_DATE ('2013-6-13 16:30:00', 'yyyy-MM-dd hh24:mi:ss'),
input = 0,
output = 0,
fpy = 1,
uph = 107,
upph = 4
WHERE start_time =
TO_DATE ('2013-6-13 15:30:00', 'yyyy-MM-dd hh24:mi:ss');
ELSE
INSERT INTO glb_rpt_uph
VALUES ('AK73-BTE-EA1', 'd',
TO_DATE ('2013-6-13 15:30:00', 'yyyy-MM-dd hh24:mi:ss'),
TO_DATE ('2013-6-13 16:30:00', 'yyyy-MM-dd hh24:mi:ss'),
0, 0, 1, 107, 4);
END IF;
END;
拋去字段部份,格式都一樣,自己根據實際需要修改吧