String MySQLConnectionString = global::MyPersonnel.Properties.Settings.Default.MyPersonnelConnectionString;
SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
MyConnection.Open();
My员工编号 = this.基本档案DataGridView.CurrentRow.Cells[1].Value.ToString();
string MySql = "select count(*) from @表名 where 员工编号= '" + My员工编号 + "'";
SqlCommand MyCommand = MyConnection.CreateCommand();
MyCommand.CommandText = MySql;
MyCommand.Parameters.Add(new SqlParameter("@表名", SqlDbType.VarChar)); //运行到下面这行提示错误,没有给 @表名 赋值
MyCommand.Parameters["@表名"].Value = "工资发放表"; //赋值为一个表的名字
工资发放表Result=Convert.ToInt32(MyCommand.ExecuteScalar());//计算能否查到结果 MyCommand.Parameters["@表名"].Value = "工资核算表"; //赋值为另一个表的名字
工资核算表Result = Convert.ToInt32(MyCommand.ExecuteScalar());//再次计算能否查到结果以上错误怎么改正呢?高人指点,这个写法应该没错误的吧
SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
MyConnection.Open();
My员工编号 = this.基本档案DataGridView.CurrentRow.Cells[1].Value.ToString();
string MySql = "select count(*) from @表名 where 员工编号= '" + My员工编号 + "'";
SqlCommand MyCommand = MyConnection.CreateCommand();
MyCommand.CommandText = MySql;
MyCommand.Parameters.Add(new SqlParameter("@表名", SqlDbType.VarChar)); //运行到下面这行提示错误,没有给 @表名 赋值
MyCommand.Parameters["@表名"].Value = "工资发放表"; //赋值为一个表的名字
工资发放表Result=Convert.ToInt32(MyCommand.ExecuteScalar());//计算能否查到结果 MyCommand.Parameters["@表名"].Value = "工资核算表"; //赋值为另一个表的名字
工资核算表Result = Convert.ToInt32(MyCommand.ExecuteScalar());//再次计算能否查到结果以上错误怎么改正呢?高人指点,这个写法应该没错误的吧
MyCommand.Parameters.Add(new SqlParameter("@表名", SqlDbType.VarChar));
你现在只是给它添加了这个参数,但你没有复制value。
new SqlParameter("@表名", SqlDbType.VarChar)
旧不用了,到时候直接给tablename 复制即可。
@符号这样用"select count(*) from "+tablename+" where 员工编号= @employeename";
MyCommand.Parameters.Add(new SqlParameter("@employeename", SqlDbType.VarChar));
这样就是赋值啊,不对吗?
parm3.Value = argFBCID;
我现在只是要不断变化表名执行这个查询,直接用一般的变量就应该就可以了吧,马上试下....