I am developing a Windows Forms application in C#. I have always encryption columns in SQL Server.
My goal is to pull data from the datagridview in the form and display data.
I want to pull the data with the where operator and display it in the datagridview, but I am getting the following error. Is there any way to do this?
I would be glad if you help!!
Error
System.Data.SqlClient.SqlException: 'Must declare the scalar variable "@SSN".
Code:
private void btnSearch_Click(object sender, EventArgs e)
{
con = new SqlConnection("Data Source = " + IP + "; Initial Catalog = " + db + "; Persist Security Info = False; User ID = " + username + "; Password = " + password + ";Column Encryption Setting = Enabled;");
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = @"SELECT* FROM AE WHERE TEST_TYPE = @SSN";
SqlParameter paramSSN = cmd.CreateParameter();
paramSSN.ParameterName = @"@SSN";
//paramSSN.ParameterName = "@SSN";
paramSSN.DbType = DbType.AnsiStringFixedLength;
paramSSN.Direction = ParameterDirection.Input;
paramSSN.Value = "'INITIAL_TEST'";
paramSSN.Size = 18;
DataSet data_set = new DataSet(cmd.CommandText);
dataAdapter = new SqlDataAdapter(cmd.CommandText,con);
SqlCommandBuilder commandbuild = new SqlCommandBuilder(dataAdapter);
dataAdapter.Fill(data_set);
dataGridView1.DataSource = data_set.Tables[0].DefaultView;
int rowCount = data_set.Tables[0].Rows.Count;
label6.Text = rowCount.ToString();//Total record
con.Close();
}
}