我的登录系统有问题.我制作了一个运行良好的简单系统,但我想让它更高级,并根据用户的不同显示不同的起始页面UserType.但是,我遇到以下错误:"必须声明标量变量@UserType."
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class LoginwithEncryption : System.Web.UI.Page
{
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand(
"select * from dbo.UserInfo where Login =@Login and UserType=@UserType and Password=@Password and UserType=@UserType", con);
cmd.Parameters.AddWithValue("@Login", txtUserName.Text);
cmd.Parameters.AddWithValue("@Password", txtPWD.Text+".123");
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
int usertype = Convert.ToInt32(dt.Rows[0]["UserType"]);
if (usertype == 1)
{
Response.Redirect("StartPage.aspx"); …Run Code Online (Sandbox Code Playgroud) 当我尝试将数据从textfile移动到arraylist时,我在行data.add(row)上得到错误; (找不到合适的方法)我该如何解决?如果我想用它来填充java jtable(swing),那么使用arraylist是个好主意吗?
public ArrayList<String> getinformationforthetable() {
Scanner s = null;
ArrayList<String> data = new ArrayList<String>();
try {
s = new Scanner(new File("info.txt"));
while (s.hasNextLine()) {
String line = s.nextLine();
if (line.startsWith("")) {
String[] atoms = line.split("[#]");
ArrayList<String> row = new ArrayList<String>();
row.add(atoms[0]);
row.add(atoms[1]);
row.add(atoms[2]);
row.add(atoms[3]);
row.add(atoms[4]);
row.add(atoms[5]);
data.add(row);
}
}
}
catch(IOException e) {
e.printStackTrace();
}
finally {
if (s != null) {
s.close();
}
}
return data;
}
}
Run Code Online (Sandbox Code Playgroud)