I have a problem. How to use variable in SQL question? This code doesn't work:
cmd.CommandText = "select Id, Name from tblFiles WHERE email = 'CurrentUser'";
cmd.CommandText = "select Id, Name from tblFiles WHERE email = '+CurrentUser'";
cmd.CommandText = "select Id, Name from tblFiles WHERE email = '$CurrentUser'";
cmd.CommandText = "select Id, Name from tblFiles WHERE email =' +CurrentUser'";
cmd.CommandText = "select Id, Name from tblFiles WHERE email = CurrentUser";
I must download from database date where email is CurrentUser = User.Identity.Name.
private void BindGrid()
{
string CurrentUser = User.Identity.Name;
string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
if (CurrentUser != null)
{
using (SqlCommand cmd = new SqlCommand())
{
GridView GridView1 = LoginView3.FindControl("GridView1") as GridView;
cmd.CommandText = "select Id, Name from tblFiles WHERE email = 'CurrentUser'";
cmd.Connection = con;
con.Open();
GridView1.DataSource = cmd.ExecuteReader();
GridView1.DataBind();
con.Close();
}
}
}
}
cmd.CommandText = string.Format("select Id, Name from tblFiles WHERE email = '{0}'", CurrentUser);