sql = "select woid,woname from [L_Workshop] where woname='" + comboBox1.Text + "'";//查询所选择的部门的ID
rs = new SqlDataAdapter(sql, conn);
rs.Fill(myDataSet, "L_Workshop");
myBind = this.BindingContext[myDataSet, "L_Workshop"];
int aa=0;
if (myBind.Count > 0)
{
aa = Convert.ToInt32(myDataSet.Tables["L_Workshop"].Rows[0]["woid"].ToString());
} if (publicclass.pass == "") //如果是添加
{
sql = "insert into [L_Employ] (emcode,emname,woid)"
+ " values ('" + textBox1.Text + "','" + textBox2.Text + "'," + aa + ")";
}
else //如果是修改
{
sql = "update [L_Employ] set emcode='" + textBox1.Text + "',emname='" + textBox2.Text+"',"
+ "woid=" + aa + " where emid=" + publicclass.pass;
}
rs = new SqlDataAdapter(sql, conn);
rs.Fill(myDataSet, "L_Employ");
myBind = this.BindingContext[myDataSet, "L_Employ"];++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++sql = "select teid,tename from [L_Technology] where tename='" + comboBox1.Text + "'";//查询所选择的工艺的ID
myDataSet = new DataSet();
rs = new SqlDataAdapter(sql, conn);
rs.Fill(myDataSet, "L_Technology");
myBind = this.BindingContext[myDataSet, "L_Technology"];
int aa=0;
if (myBind.Count > 0)
{
aa = Convert.ToInt32(myDataSet.Tables["L_Technology"].Rows[0]["teid"].ToString());
} if (publicclass.pass == "") //如果是添加
{
sql = "insert into [L_Process] (prcode,prname,zid,teid)"
+ " values ('" + textBox1.Text + "','" + textBox2.Text + "'," + textBox3.Text + "," + aa + ")";
}
else //如果是修改
{
sql = "update [L_Process] set prcode='" + textBox1.Text + "',prname='" + textBox2.Text+"',"
+ "zid=" + textBox3.Text + ",teid=" + aa + " where prid=" + publicclass.pass;
}
rs = new SqlDataAdapter(sql, conn);’过滤此处
rs.Fill(myDataSet, "L_Process");
myBind = this.BindingContext[myDataSet, "L_Process"];
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
以上两段代码,基本相同,但是第一段代码执行无误,第二段就提示无法创建字段***的子表,后来发现当过滤掉上面的 rs = new SqlDataAdapter(sql, conn);时候就正常了~~~
为啥??
rs = new SqlDataAdapter(sql, conn);
rs.Fill(myDataSet, "L_Workshop");
myBind = this.BindingContext[myDataSet, "L_Workshop"];
int aa=0;
if (myBind.Count > 0)
{
aa = Convert.ToInt32(myDataSet.Tables["L_Workshop"].Rows[0]["woid"].ToString());
} if (publicclass.pass == "") //如果是添加
{
sql = "insert into [L_Employ] (emcode,emname,woid)"
+ " values ('" + textBox1.Text + "','" + textBox2.Text + "'," + aa + ")";
}
else //如果是修改
{
sql = "update [L_Employ] set emcode='" + textBox1.Text + "',emname='" + textBox2.Text+"',"
+ "woid=" + aa + " where emid=" + publicclass.pass;
}
rs = new SqlDataAdapter(sql, conn);
rs.Fill(myDataSet, "L_Employ");
myBind = this.BindingContext[myDataSet, "L_Employ"];++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++sql = "select teid,tename from [L_Technology] where tename='" + comboBox1.Text + "'";//查询所选择的工艺的ID
myDataSet = new DataSet();
rs = new SqlDataAdapter(sql, conn);
rs.Fill(myDataSet, "L_Technology");
myBind = this.BindingContext[myDataSet, "L_Technology"];
int aa=0;
if (myBind.Count > 0)
{
aa = Convert.ToInt32(myDataSet.Tables["L_Technology"].Rows[0]["teid"].ToString());
} if (publicclass.pass == "") //如果是添加
{
sql = "insert into [L_Process] (prcode,prname,zid,teid)"
+ " values ('" + textBox1.Text + "','" + textBox2.Text + "'," + textBox3.Text + "," + aa + ")";
}
else //如果是修改
{
sql = "update [L_Process] set prcode='" + textBox1.Text + "',prname='" + textBox2.Text+"',"
+ "zid=" + textBox3.Text + ",teid=" + aa + " where prid=" + publicclass.pass;
}
rs = new SqlDataAdapter(sql, conn);’过滤此处
rs.Fill(myDataSet, "L_Process");
myBind = this.BindingContext[myDataSet, "L_Process"];
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
以上两段代码,基本相同,但是第一段代码执行无误,第二段就提示无法创建字段***的子表,后来发现当过滤掉上面的 rs = new SqlDataAdapter(sql, conn);时候就正常了~~~
为啥??
解决方案 »
- DataGridView行颜色改变问题
- 【经典】WebRequest读取网页不完整,而webclick却完全正常
- C# Textbox数据绑定问题
- 怎样手工修改dataset中的datatable?急!
- 请问如何生成一个程序
- 怎么样监测网络是否连接?
- sp商通过ie浏览器传过来的参数用java编码(gb2312)后,到我们这边的数据库里就变成??,我们这边程序用c#写的,应该要用decode解码,可是我试过
- 在不用多线程的情况下怎么让进程睡眠?
- 在一个网站项目上同时使用用C#与VB.net一起开发,是否可行?
- C#在web上的一个小问题
- C# winfrom怎么样登入网站然后获取网页的内容
- C# 使用UDP多端口异步监听,请教高手,急用!~
啥意思?注释?
没这句,adapter的sql没变化啊
SqlDataAdapter Constructor (String, SqlConnection)
http://msdn.microsoft.com/en-us/library/kx703tc9.aspx下面的话来自上面的链接:
SqlDataAdapter Constructor (String, SqlConnection)
Initializes a new instance of the SqlDataAdapter class with a SelectCommand and a SqlConnection object.selectCommandText
Type: System.String
A String that is a Transact-SQL SELECT statement or stored procedure to be used by the SelectCommand property of the SqlDataAdapter. .....
InsertCommand和UpdateCommand还有DeleteCommand可以通过属性复制,但是不能传给构造函数。
public static SqlDataAdapter CreateSqlDataAdapter(string commandText,
SqlConnection connection)
{
SqlDataAdapter adapter = new SqlDataAdapter(commandText, connection); adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; // Create the other commands.
adapter.InsertCommand = new SqlCommand(
"INSERT INTO Customers (CustomerID, CompanyName) " +
"VALUES (@CustomerID, @CompanyName)"); adapter.UpdateCommand = new SqlCommand(
"UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName " +
"WHERE CustomerID = @oldCustomerID"); adapter.DeleteCommand = new SqlCommand(
"DELETE FROM Customers WHERE CustomerID = @CustomerID"); // Create the parameters.
adapter.InsertCommand.Parameters.Add("@CustomerID",
SqlDbType.Char, 5, "CustomerID");
adapter.InsertCommand.Parameters.Add("@CompanyName",
SqlDbType.VarChar, 40, "CompanyName"); adapter.UpdateCommand.Parameters.Add("@CustomerID",
SqlDbType.Char, 5, "CustomerID");
adapter.UpdateCommand.Parameters.Add("@CompanyName",
SqlDbType.VarChar, 40, "CompanyName");
adapter.UpdateCommand.Parameters.Add("@oldCustomerID",
SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original; adapter.DeleteCommand.Parameters.Add("@CustomerID",
SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original; return adapter;
}