我做一个简单的登录

程序小海 2009-11-15 10:57:55
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace ADL
{
public class lognAdl
{
public void logn_sql(string userName, string password)
{
string str = "server=.;database=" + userName + ";uid=sa;" + password;
SqlConnection conn = new SqlConnection(str);
conn.Open();

}
}
}
DAL类库中的数据


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

namespace BLL
{
public class Logn
{
public void bllogn(string userName,string passwoed)
{
if (userName == "" || passwoed == "")
{
throw new Exception("请输入正确!");
}
ADL.lognAdl lad = new ADL.lognAdl();
lad.logn_sql(userName, passwoed);
}

}
}
BLL类库中的数据


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 学生管理系统
{
public partial class Log_on : Form
{
public Log_on()
{
InitializeComponent();
}

private void Logn_Click(object sender, EventArgs e)
{
BLL.Logn ln = new BLL.Logn();

try
{
ln.bllogn(textBox1.Text, textBox2.Text);
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
}
}
主窗体的代码

运行的时候会报错说 33行 初始化字符串格式不符合规格 ???
...全文
99 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ginni215 2009-11-15
  • 打赏
  • 举报
回复
string str = "server=.;database=" + userName + ";uid=sa;" + password;
应该是这里错了~~
程序小海 2009-11-15
  • 打赏
  • 举报
回复
今天 真丢人 全部说些 无聊的问题!
wiki14 2009-11-15
  • 打赏
  • 举报
回复
LS都说了。
风骑士之怒 2009-11-15
  • 打赏
  • 举报
回复
string str = "Data Source=.;Initial Catalog=dbname;User ID=sa;Password=sa";
红街咖啡 2009-11-15
  • 打赏
  • 举报
回复
链接字符串错误。
wuyq11 2009-11-15
  • 打赏
  • 举报
回复
string str = "server=.;database=" + userName + ";uid=sa;" + password;
这是连接字符串
string str = "Data Source=(local);Initial Catalog=test;User ID=sa;Password=sa";
server=.;database=test;uid=sa;pwd=sa;

17,748

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧