我想要在代碼中獲取cmdd(@PermissionAccessoageID)值,以及如何實現這一點。在c#中的where子句中檢索特定值
我得到這個錯誤
類型「System.ArgumentException」的異常出現在System.Data.dll中,但在用戶代碼中沒有處理
其它信息:沒有映射從對象類型存在System.Data.SqlClient.SqlCommand添加到已知的託管提供程序本機類型。
我的代碼:
protected void Add_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[1] { new DataColumn("Pages") });
foreach (GridViewRow row in addGridView.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox chkRow = (row.Cells[1].FindControl("chkboxaddView") as CheckBox);
CheckBox chkRow1 = (row.Cells[2].FindControl("chkboxaddEdit") as CheckBox);
string aaa = row.Cells[0].Text;
if (chkRow.Checked)
{
con.Open();
var vaala = chkRow.Checked ? 1 : 0;
var vaalaa = chkRow1.Checked ? 1 : 0;
var val = chkaddisactive.Checked ? 1 : 0;
var vall = chkboxisactive.Checked ? 1 : 0;
string sqlcmd = "select AccesspageID From AccessPages where pages='" + row.Cells[0].Text + "'";
SqlCommand cmdd = new SqlCommand(sqlcmd, con);
cmdd.CommandType = CommandType.Text;
cmdd.ExecuteScalar();
string query = "add3tables"; //Stored procedure name
SqlCommand com = new SqlCommand(query, con); //creating SqlCommand object
com.CommandType = CommandType.StoredProcedure; //here we declaring command type as stored procedure
// adding parameters to SqlCommand below
com.Parameters.AddWithValue("@Name", txtaddrolename.Text.ToString());
string unique_string = Guid.NewGuid().ToString();
com.Parameters.AddWithValue("@RoleID ", unique_string);
com.Parameters.AddWithValue("@IsActive ", val);
com.Parameters.AddWithValue("@PermissionRoleID ", unique_string);
com.Parameters.AddWithValue("@View ", vaala);
com.Parameters.AddWithValue("@Edit ", vaalaa);
com.Parameters.AddWithValue("@PermissionAccessoageID ", cmdd);
com.ExecuteNonQuery();
con.Close();
}
if (chkRow1.Checked == false)
{
var vaala = chkRow.Checked ? 1 : 0;
var vaalaa = chkRow1.Checked ? 1 : 0;
var val = chkaddisactive.Checked ? 1 : 0;
var vall = chkboxisactive.Checked ? 1 : 0;
SqlCommand cmdd = new SqlCommand("select AccesspageID From AccessPages where pages='" + aaa + "'", con);
con.Open();
cmdd.CommandType = CommandType.Text;
string query = "add3tables"; //Stored procedure name
SqlCommand com = new SqlCommand(query, con); //creating SqlCommand object
com.CommandType = CommandType.StoredProcedure; //here we declaring command type as stored procedure
// adding parameters to SqlCommand below
com.Parameters.AddWithValue("@Name", txtaddrolename.Text.ToString());
string unique_string = Guid.NewGuid().ToString();
com.Parameters.AddWithValue("@RoleID ", unique_string);
com.Parameters.AddWithValue("@IsActive ", val);
com.Parameters.AddWithValue("@PermissionRoleID ", unique_string);
com.Parameters.AddWithValue("@View ", vaala);
com.Parameters.AddWithValue("@Edit ", vaalaa);
com.Parameters.AddWithValue("@PermissionAccessoageID ", cmdd);
com.ExecuteNonQuery();
con.Close();
}
}
您能詳細說明爲什麼要獲取cmdd(@PermissionAccessoageID)的值嗎?它是最後插入的行還是別的東西? –
Cmdd已在數據庫中插入行。我想檢索AccesspageID – Vinoth
您的第一個選擇語句似乎是無用的。你從不在代碼中的任何地方使用結果。在你的第二條if語句中,你甚至不執行它。 – Marco