C# asp中的登录名和密码 我有一个代码C的标准来登录但不工作,它给了我另外的消息: protected void Button1_Click(object sender, EventArgs e) { string Connection = @"data source=LOCALHOST;initial catalog=CVtech;Integrated Security=false;User ID=sa;Password=123"; string Requete = "select * from Agent where Login ='" + UserLogin.Text + " and PPR = " + UserPass.Text+"'"; SqlDataAdapter da = new SqlDataAdapter(Requete, Connection); DataSet Ds = new DataSet(); da.Fill(Ds); if (Ds.Tables[0].Rows.Count > 0) { DataRow[] dr = Ds.Tables[0].Select(); Session["Code"] = dr[0]["PPR"].ToString(); Response.Redirect("cv.aspx"); } else { Response.Write(" message d'erreur login et mot de passe erroné"); } }

C# asp中的登录名和密码 我有一个代码C的标准来登录但不工作,它给了我另外的消息: protected void Button1_Click(object sender, EventArgs e) { string Connection = @"data source=LOCALHOST;initial catalog=CVtech;Integrated Security=false;User ID=sa;Password=123"; string Requete = "select * from Agent where Login ='" + UserLogin.Text + " and PPR = " + UserPass.Text+"'"; SqlDataAdapter da = new SqlDataAdapter(Requete, Connection); DataSet Ds = new DataSet(); da.Fill(Ds); if (Ds.Tables[0].Rows.Count > 0) { DataRow[] dr = Ds.Tables[0].Select(); Session["Code"] = dr[0]["PPR"].ToString(); Response.Redirect("cv.aspx"); } else { Response.Write(" message d'erreur login et mot de passe erroné"); } },c#,asp.net,sql-server,C#,Asp.net,Sql Server,我有一个登录名:Ach和PPR=1 谢谢您没有关闭sql请求中的字符串值 string Requete = "select * from Agent where Login ='" + UserLogin.Text + " and PPR = " + UserPass.Text + "'"; 应该是 string Requete = "select * from Agent where Login ='" + UserLogin.Text + "' and PPR = '" + UserPas

我有一个登录名:Ach和PPR=1


谢谢

您没有关闭sql请求中的字符串值

string Requete = "select * from Agent where Login ='" + UserLogin.Text + " and PPR = " + UserPass.Text + "'";
应该是

string Requete = "select * from Agent where Login ='" + UserLogin.Text + "' and PPR = '" + UserPass.Text + "'";
此外,您还应该研究sql注入和查询参数化。我不经常使用DataAdapter,但我相信它看起来会像

SqlConnection connection = new SqlConnection("data source=LOCALHOST;initial catalog=CVtech;Integrated Security=false;User ID=sa;Password=123");
SqlDataAdapter da = new SqlDataAdapter(); 

SqlCommand command = new SqlCommand("select * from Agent where Login = @login and PPR = @ppr", connection);

command.Parameters.Add("@login", SqlDbType.NVarChar, 50);
command.Parameters["@login"].Value = UserLogin.Text;

command.Parameters.Add("@ppr", SqlDbType.NVarChar, 50);
command.Parameters["@ppr"].Value = UserPass.Text;

da.SelectCommand = command;

DataSet Ds = new DataSet(); 
da.Fill(Ds);
有关更多详细信息,请参阅

如何:在ASP.NET中防止SQL注入

SqlDataAdapter.SelectCommand属性


您没有关闭sql请求中的字符串值

string Requete = "select * from Agent where Login ='" + UserLogin.Text + " and PPR = " + UserPass.Text + "'";
应该是

string Requete = "select * from Agent where Login ='" + UserLogin.Text + "' and PPR = '" + UserPass.Text + "'";
此外,您还应该研究sql注入和查询参数化。我不经常使用DataAdapter,但我相信它看起来会像

SqlConnection connection = new SqlConnection("data source=LOCALHOST;initial catalog=CVtech;Integrated Security=false;User ID=sa;Password=123");
SqlDataAdapter da = new SqlDataAdapter(); 

SqlCommand command = new SqlCommand("select * from Agent where Login = @login and PPR = @ppr", connection);

command.Parameters.Add("@login", SqlDbType.NVarChar, 50);
command.Parameters["@login"].Value = UserLogin.Text;

command.Parameters.Add("@ppr", SqlDbType.NVarChar, 50);
command.Parameters["@ppr"].Value = UserPass.Text;

da.SelectCommand = command;

DataSet Ds = new DataSet(); 
da.Fill(Ds);
有关更多详细信息,请参阅

如何:在ASP.NET中防止SQL注入

SqlDataAdapter.SelectCommand属性


您没有关闭sql请求中的字符串值

string Requete = "select * from Agent where Login ='" + UserLogin.Text + " and PPR = " + UserPass.Text + "'";
应该是

string Requete = "select * from Agent where Login ='" + UserLogin.Text + "' and PPR = '" + UserPass.Text + "'";
此外,您还应该研究sql注入和查询参数化。我不经常使用DataAdapter,但我相信它看起来会像

SqlConnection connection = new SqlConnection("data source=LOCALHOST;initial catalog=CVtech;Integrated Security=false;User ID=sa;Password=123");
SqlDataAdapter da = new SqlDataAdapter(); 

SqlCommand command = new SqlCommand("select * from Agent where Login = @login and PPR = @ppr", connection);

command.Parameters.Add("@login", SqlDbType.NVarChar, 50);
command.Parameters["@login"].Value = UserLogin.Text;

command.Parameters.Add("@ppr", SqlDbType.NVarChar, 50);
command.Parameters["@ppr"].Value = UserPass.Text;

da.SelectCommand = command;

DataSet Ds = new DataSet(); 
da.Fill(Ds);
有关更多详细信息,请参阅

如何:在ASP.NET中防止SQL注入

SqlDataAdapter.SelectCommand属性


您没有关闭sql请求中的字符串值

string Requete = "select * from Agent where Login ='" + UserLogin.Text + " and PPR = " + UserPass.Text + "'";
应该是

string Requete = "select * from Agent where Login ='" + UserLogin.Text + "' and PPR = '" + UserPass.Text + "'";
此外,您还应该研究sql注入和查询参数化。我不经常使用DataAdapter,但我相信它看起来会像

SqlConnection connection = new SqlConnection("data source=LOCALHOST;initial catalog=CVtech;Integrated Security=false;User ID=sa;Password=123");
SqlDataAdapter da = new SqlDataAdapter(); 

SqlCommand command = new SqlCommand("select * from Agent where Login = @login and PPR = @ppr", connection);

command.Parameters.Add("@login", SqlDbType.NVarChar, 50);
command.Parameters["@login"].Value = UserLogin.Text;

command.Parameters.Add("@ppr", SqlDbType.NVarChar, 50);
command.Parameters["@ppr"].Value = UserPass.Text;

da.SelectCommand = command;

DataSet Ds = new DataSet(); 
da.Fill(Ds);
有关更多详细信息,请参阅

如何:在ASP.NET中防止SQL注入

SqlDataAdapter.SelectCommand属性



尝试调试代码,显然行数为0。另外,请修复以下问题:string Requete=select*来自代理,其中Login='+UserLogin.Text+和PPR=+UserPass.Text+';您正在请求SQL注入。您应该始终使用。这种类型的字符串连接会受到攻击。请检查您创建的sql字符串-您将看到缺少一些引号。请尝试调试代码,显然行数为0。另外,请修复以下问题:string Requete=select*来自代理,其中Login='+UserLogin.Text+和PPR=+UserPass.Text+';您正在请求SQL注入。您应该始终使用。这种类型的字符串连接会受到攻击。请检查您创建的sql字符串-您将看到缺少一些引号。请尝试调试代码,显然行数为0。另外,请修复以下问题:string Requete=select*来自代理,其中Login='+UserLogin.Text+和PPR=+UserPass.Text+';您正在请求SQL注入。您应该始终使用。这种类型的字符串连接会受到攻击。请检查您创建的sql字符串-您将看到缺少一些引号。请尝试调试代码,显然行数为0。另外,请修复以下问题:string Requete=select*来自代理,其中Login='+UserLogin.Text+和PPR=+UserPass.Text+';您正在请求SQL注入。您应该始终使用。这种类型的字符串连接容易受到攻击。请检查您创建的sql字符串-您将看到缺少一些引号。请注意上面的建议并使用SQLParameters+1是的。也考虑用示例来建议他参数化的查询。不,我在DA。fILDs中有这个错误;La requète paramétrée'@login varchar50,@ppr intselect*from Agent where login=@'参加leparamètre@login,qui n'a pasétéfourni.仔细检查上面的代码,我认为您使用的不是最新版本。请注意上面的建议并使用SQLParameters+1是的。也考虑用示例来建议他参数化的查询。不,我在DA。fILDs中有这个错误;La requète paramétrée'@login varchar50,@ppr intselect*from Agent where login=@'参加leparamètre@login,qui n'a pasétéfourni.仔细检查上面的代码,我认为您使用的不是最新版本。请注意上面的建议并使用SQLParameters+1是的。也考虑用示例来建议他参数化的查询。不,我在DA。fILDs中有这个错误;La requète paramétrée'@login varchar50,@ppr intselect*from Agent where login=@'参加leparamètre@login,qui n'a pasétéfourni.仔细检查上面的代码,我认为您使用的不是最新版本。请注意上面的建议并使用SQLParameters+1是的。也考虑用示例来建议他参数化的查询。不,我在DA。fILDs中有这个错误;La requète paramétrée'@login varchar50,@ppr intselect*from Agent where login=@'attent le paramètre@login,qui n'a pasétéfourni.仔细检查上述代码,我认为您使用的不是最新版本。