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;namespace WindowsApplication1
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
public string table = "";
private void btnDel_Click(object sender, EventArgs e)
{
table = "TB_EMP";
string empId = textID.Text;
string empName = textName.Text;
string empSal = textSal.Text;
string empSex = textSex.Text;
string empBirthday = textBirthday.Text;
string str = "Server= LYP19900208;DataBase=test01;Uid=sa;Pwd=6020";
SqlConnection conn = null;
conn = new SqlConnection(str);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
cmd.CommandText = "delete '" + table + "' where (empID = '" + empId + "') ";
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds,table);
MessageBox.Show("删除成功!");
}
}
}
这是我的代码,运行的时候总是提示我sql语句出错,求解
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace WindowsApplication1
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
public string table = "";
private void btnDel_Click(object sender, EventArgs e)
{
table = "TB_EMP";
string empId = textID.Text;
string empName = textName.Text;
string empSal = textSal.Text;
string empSex = textSex.Text;
string empBirthday = textBirthday.Text;
string str = "Server= LYP19900208;DataBase=test01;Uid=sa;Pwd=6020";
SqlConnection conn = null;
conn = new SqlConnection(str);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
cmd.CommandText = "delete '" + table + "' where (empID = '" + empId + "') ";
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds,table);
MessageBox.Show("删除成功!");
}
}
}
这是我的代码,运行的时候总是提示我sql语句出错,求解
解决方案 »
- 求教,C# ,怎么通过button_Click事件跳转到另一个命名空间的form
- foreach (DataRow row in dt.Rows){}只能读到第一行 咋回事 sql语句正常
- 我机器上先安装的vs2010后安装的vs2008,但现在打开vs2008做的项目解决方案.snl默认是vs2010打开方式,如何修改打开方式默认为vs2008
- 如何获取有效字段
- TCPConnection 连接IP的问题
- 新手:webbrowser如何使用?
- 急!!想用C#做一个WinForm窗体控件.还请各位高手帮忙.
- 求助:为什么VISUAL STUDIO .NET 2003装不了?
- 如何在winform窗体中嵌入一个流览文件属性的文件夹.有这种文件夹控件吗?
- 请问,线程A中新建了一个对象C,线程B中添加了对象C的引用,如何在线程B中调用C的某个函数,让这个函数在线程A中执行,谢谢!
- BatchExecNonQuery
- 菜鸟求救
cmd.CommandText = "delete " + table + " where empID = '" + empId + "' ";
sql语句 删除是这样写的
delete from table where tableid='';
table是不需要加引号的
"delete table where empID='"+empId+"'";
//删除table中的符合条件的记录"drop "+table
//删除table