请教一个登陆的问题急! 看了一个登陆验证的视频 想请教如果我想实现第一次登陆需要出现 数据库服务器,数据库名,数据库用户名,数据库密码 验证通过后出现用户名,和密码的登陆框 以后在登陆只需要登陆用户名和密码,如何实现啊 请高手帮忙啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 LZ是想先进行服务器配置再进行用户登陆是吧?再多加个FORM就行了啊。不过还是建议LZ把服务器选择写进REGEDIT,以便于管理,大不了在登陆窗口加一个键以启动服务器选择窗口就行了。 大家能不能说的详细点 我很菜 想实现c/s模式 数据库用sql 2000 谢谢了 FORM.csDataSeverce ds = new DataSeverce();Sever = this.textBox1.Text.Trim();DataBase = this.textBox2.Text.Trim();User = this.textBox3.Text.Trim();Psd = this.textBox4.Text.Trim();DataSeverce.DataSeverceCon("Server=" + Sever + ";database=" + DataBase + ";uid=" + User + ";pwd=" + Psd, true).Close(); ds._Sever = Sever;//类的属性ds._DataBase = DataBase;ds._User = User;ds._Psd = Psd; public class DataSeverce { private static string Sever; public string _Sever { get { return Sever; } set { Sever = value; } } private static string DataBase; public string _DataBase { get { return DataBase; } set { DataBase = value; } } private static string User; public string _User { get { return User; } set { User = value; } } private static string Psd; public string _Psd { get { return Psd; } set { Psd = value; } } public static SqlConnection DataSeverceConn() { try { SqlConnection conn = new SqlConnection("Server=" + Sever + ";database=" + DataBase + ";uid=" + User + ";pwd=" + Psd); conn.Open(); return conn; } catch(Exception ex) { MessageBox.Show("请先连接数据库,"+ex.Message.ToString(), "错误"); return null; } } 修改下,把数据库连接信息保存在XML中吧 你可以在第一次登入的时候把服务器的信息记录到.txt的文本里面,以后登入的话只要去捞取文本信息就可以了 我对xml不熟悉 ,能给个例子吗 第一次输入后将相关连接信息保存在XML文件里,下次直接读出就可以 建一个XML<sqlsever DocID="1"> <path server="",database="",uid="",psd=""></sqlsever>from.csDataSeverce ds = new DataSeverce(); protected void Button1_Click(object sender, EventArgs e) { string Sever = this.textBox1.Text.Trim(); string DataBase = this.textBox2.Text.Trim(); sring User = this.textBox3.Text.Trim(); sring Psd = this.textBox4.Text.Trim(); private XmlNode xn,xn2 XmlDocument xdc = new XmlDocument(); xdc.Load(Application.StartupPath + "//Path.xml"); xn = xdc.SelectSingleNode("//sqlsever[@DocID='1']"); XmlNodeList xnl = xn.ChildNodes; for (int i = 0; i < nodes.Count; i++) { XmlAttribute att = nodes[i].Attributes[ "sever"]; XmlAttribute att2 = nodes[i].Attributes[ "database"]; XmlAttribute att3 = nodes[i].Attributes[ "uid"]; XmlAttribute att4 = nodes[i].Attributes[ "psd"]; if (att.Value == "") { att.Value = "F "; break; } else { ds._Sever = Sever;//类的属性 ds._DataBase = DataBase; ds._User = User; ds._Psd = Psd; } } //保存上面的修改 xdc.Save(Application.StartupPath + "//Path.xml");); }没环境 可能有语法错误 XmlNodeList xnl = xn.ChildNodes; 改成 nodesXmlNodeList nodes = xn.ChildNodes; 建的那个XML文件需要放在你项目的 \bin\Debug 文件夹下 整理下重发建一个XML <sqlsever DocID="1"> <path server="",database="",uid="",psd=""> </sqlsever> from.cs DataSeverce ds = new DataSeverce(); protected void Button1_Click(object sender, EventArgs e) { string Sever = this.textBox1.Text.Trim(); string DataBase = this.textBox2.Text.Trim(); sring User = this.textBox3.Text.Trim(); sring Psd = this.textBox4.Text.Trim(); private XmlNode xn,xn2 XmlDocument xdc = new XmlDocument(); xdc.Load(Application.StartupPath + "//Path.xml"); xn = xdc.SelectSingleNode("//sqlsever[@DocID='1']"); XmlNodeList nodes = xn.ChildNodes; for (int i = 0; i < nodes.Count; i++) { XmlAttribute att = nodes[i].Attributes[ "sever"]; XmlAttribute att2 = nodes[i].Attributes[ "database"]; XmlAttribute att3 = nodes[i].Attributes[ "uid"]; XmlAttribute att4 = nodes[i].Attributes[ "psd"]; if (att.Value == "") { att.Value = Sever; att1.value = database; att2.value = User; att3.value = Psd; break; } else { ds._Sever = att.Value;//类的属性 ds._DataBase = att1.value; ds._User = att2.value; ds._Psd = att3.value; } } //保存上面的修改 xdc.Save(Application.StartupPath + "//Path.xml");); } 第一次输入写入xml文件writexml()下次用readxml()读出; listBox分页显示的问题,C# Asp.net 怎么将代码写的Html语言 在页面上显示 工作组模式下,如何访问远程的MSMQ winform 套打方案 .net web 程序中弹出对话框怎么写 怎样将我在Form上某一个区域绘制的图象,保存到Image中?急!!!在线等!!!真的很着急!分不够加!!! winform如何编写类似vb里面的Resize事件? 关于数据库的问题,会的人请进(在线等) 关于DESCryptoServiceProvider加密的问题 如何在c#里面设置堆栈的大小?? image edit out of memory 如何格式化时间?
Sever = this.textBox1.Text.Trim();
DataBase = this.textBox2.Text.Trim();
User = this.textBox3.Text.Trim();
Psd = this.textBox4.Text.Trim();
DataSeverce.DataSeverceCon("Server=" + Sever + ";database=" + DataBase + ";uid=" + User + ";pwd=" + Psd, true).Close();
ds._Sever = Sever;//类的属性
ds._DataBase = DataBase;
ds._User = User;
ds._Psd = Psd;
public class DataSeverce
{ private static string Sever; public string _Sever
{
get { return Sever; }
set { Sever = value; }
} private static string DataBase; public string _DataBase
{
get { return DataBase; }
set { DataBase = value; }
} private static string User; public string _User
{
get { return User; }
set { User = value; }
}
private static string Psd; public string _Psd
{
get { return Psd; }
set { Psd = value; }
}
public static SqlConnection DataSeverceConn()
{
try
{
SqlConnection conn = new SqlConnection("Server=" + Sever + ";database=" + DataBase + ";uid=" + User + ";pwd=" + Psd);
conn.Open();
return conn;
}
catch(Exception ex)
{
MessageBox.Show("请先连接数据库,"+ex.Message.ToString(), "错误");
return null;
}
}
你可以在第一次登入的时候把服务器的信息记录到.txt的文本里面,以后登入的话只要去捞取文本信息就可以了
<sqlsever DocID="1">
<path server="",database="",uid="",psd="">
</sqlsever>from.csDataSeverce ds = new DataSeverce();
protected void Button1_Click(object sender, EventArgs e)
{
string Sever = this.textBox1.Text.Trim();
string DataBase = this.textBox2.Text.Trim();
sring User = this.textBox3.Text.Trim();
sring Psd = this.textBox4.Text.Trim();
private XmlNode xn,xn2
XmlDocument xdc = new XmlDocument();
xdc.Load(Application.StartupPath + "//Path.xml");
xn = xdc.SelectSingleNode("//sqlsever[@DocID='1']");
XmlNodeList xnl = xn.ChildNodes;
for (int i = 0; i < nodes.Count; i++)
{
XmlAttribute att = nodes[i].Attributes[ "sever"];
XmlAttribute att2 = nodes[i].Attributes[ "database"];
XmlAttribute att3 = nodes[i].Attributes[ "uid"];
XmlAttribute att4 = nodes[i].Attributes[ "psd"];
if (att.Value == "")
{
att.Value = "F ";
break;
}
else
{
ds._Sever = Sever;//类的属性
ds._DataBase = DataBase;
ds._User = User;
ds._Psd = Psd; }
}
//保存上面的修改
xdc.Save(Application.StartupPath + "//Path.xml"););
}
没环境 可能有语法错误
<sqlsever DocID="1">
<path server="",database="",uid="",psd="">
</sqlsever> from.cs
DataSeverce ds = new DataSeverce();
protected void Button1_Click(object sender, EventArgs e)
{
string Sever = this.textBox1.Text.Trim();
string DataBase = this.textBox2.Text.Trim();
sring User = this.textBox3.Text.Trim();
sring Psd = this.textBox4.Text.Trim();
private XmlNode xn,xn2
XmlDocument xdc = new XmlDocument();
xdc.Load(Application.StartupPath + "//Path.xml");
xn = xdc.SelectSingleNode("//sqlsever[@DocID='1']");
XmlNodeList nodes = xn.ChildNodes;
for (int i = 0; i < nodes.Count; i++)
{
XmlAttribute att = nodes[i].Attributes[ "sever"];
XmlAttribute att2 = nodes[i].Attributes[ "database"];
XmlAttribute att3 = nodes[i].Attributes[ "uid"];
XmlAttribute att4 = nodes[i].Attributes[ "psd"];
if (att.Value == "")
{
att.Value = Sever;
att1.value = database;
att2.value = User;
att3.value = Psd;
break;
}
else
{
ds._Sever = att.Value;//类的属性
ds._DataBase = att1.value;
ds._User = att2.value;
ds._Psd = att3.value; }
}
//保存上面的修改
xdc.Save(Application.StartupPath + "//Path.xml"););
}
writexml()
下次用readxml()读出;