+ -
当前位置:首页 → 问答吧 → 求高手帮忙检查下错误

求高手帮忙检查下错误

时间:2011-12-18

来源:互联网

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace p358作业
{
  class zhixing
  {  
  //连接字符串
  private const string conStr = "Data Source=LIFEI-PC;Initial Catalog=Library;Persist Security Info=True;User ID=sa;Password=sa";
  #region 登录方法
  public bool login(string name,string pwd,ref string mag)
  {
  SqlConnection conn = new SqlConnection(conStr);
  try
  {
  string Sqlstr = "select count(*) from [User] where [loginId]='" + name + "'and [loginPwd]='" + pwd + "'";
  conn.Open();
  SqlCommand comm = new SqlCommand(conStr, conn);
  int Result = (int)comm.ExecuteScalar();
  if (Result != 1)
  {
  mag="登录失败!!";
  return false;
  }
  else
  {
  mag="登陆成功!!";
  return true;
  }
  }
  catch (Exception ex)
  {
  Console.WriteLine(ex.Message);
  return false;
  }
  finally
  {
  conn.Close();
  }
  #endregion
  }
  }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace p358作业
{
  class Show
  {
  zhixing z = new zhixing();
  public void showlogin()
  {
  Console.WriteLine("请输入用户名:");
  string name = Console.ReadLine();
  Console.WriteLine("请输入密码:");
  string pwd = Console.ReadLine();
  string mag = string.Empty;
  bool log = z.login(name,pwd,ref mag);
  Console.WriteLine(mag);
  if (log==true)
  {
  showlogin();
  }
  }
  }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace p358作业
{
  class Program
  {
  static void Main(string[] args)
  {
  Show s = new Show();
  s.showlogin();
  Console.ReadLine();
   
  }
  }
}
结果提示=附近有语法错误!请帮忙找下错误!谢谢

作者: javachuxuezhe_   发布时间: 2011-12-18

string Sqlstr = "select count(*) from [User] where [loginId]='" + name + "' and [loginPwd]='" + pwd + "'";

红色部分没有加空格隔开

作者: hefeng_aspnet   发布时间: 2011-12-18