0

Here is what I have so far.

//Getting access value from the AccessTable

SqlCommand cmadAccess;
string strAccess;
strAccess = "select * from AccessTable where Email='" +
    EmailTextBox.Text.Trim() + "'";
cmadAccess = new SqlCommand(strAccess, conn);
SqlDataReader readAccess = cmadAccess.ExecuteReader();
if (readAccess.Read()) {
    //here I am trying to display data from the database to the checkbox but it does not work.
}

These are two examples of what I have tried:

TechnitianCheckBox.Checked = Convert.ToBoolean(readAccess["ClientTechnitian"]);

TechnitianCheckBox.Checked = readAccess["ClientTechnitian"].ToString();

Can anyone indicate the correct way to do this?

Luca Tettamanti
  • 10,314
  • 3
  • 29
  • 25
EL Carmen
  • 11
  • 1
  • 5
  • Use parameterized queries, you're looking for injection attacks. – ragerory May 27 '15 at 12:56
  • What is the type of the column `ClientTechnitian` on your table? – Felipe Oriani May 27 '15 at 12:57
  • 2
    What exactly is the issue? TechnitianCheckBox never ends up checked as you would expect? You get an error? – sr28 May 27 '15 at 13:07
  • As mentioned by @FelipeOriani we also need to know the type of ClientTechnitian. If it's a 'bit' then it should covert quite happily to a bool, but if not then you will probably need to do some jiggery-pokery to check the checkbox or not. – sr28 May 27 '15 at 13:09
  • have you heard about SQL Injection http://stackoverflow.com/questions/601300/what-is-sql-injection – jayvee May 27 '15 at 13:19

1 Answers1

0

You're looking for GetOrdinal(...) on your reader.

TechnitianCheckBox.Checked = readAccess.GetBoolean(readAccess.GetOrdinal("ClientTechnitian"));
ragerory
  • 1,360
  • 1
  • 8
  • 27