怎么做出一个登录数据库的界面? 单击按钮,就出现一个像直接在sql serve management中连接数据库的界面(选择服务器,数据库实例,用户名和密码等),这个如何实现呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 那你还不如在程序中直接启动数据库的exe呢 楼主要的应该不是一个单纯的登录,如何来获取与数据库登录时候的密码进行比较,如何在点击事件中能够启动sql server,请大神么赐教。 http://download.csdn.net/detail/hhqsy/2631398看我的源码 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using Microsoft.Data.ConnectionUI;using System.Xml;namespace DSZQ{ public partial class DataConn : Form { public DataConn() { InitializeComponent(); //filepath = Environment.CurrentDirectory; filepath =Application.StartupPath; filepath += "//App.config"; } string filepath; string connstr; /// <summary> /// /// </summary> /// <param name="key"></param> /// <param name="strValue"></param> public void Modify(string key, string strValue) //两个参数:要修改的键值 和 要修改的新值; { string flagstr = strValue; if (strValue == string.Empty) { MessageBox.Show("连接串不能为空!"); return; } //string XPath = "/configuration/userInfo/add[@key='?']"; try { string XPath = "/configuration/appSettings/add[@key='?']"; XmlDocument domWebConfig = new XmlDocument(); //domWebConfig.Load((HttpContext.Current.Server.MapPath("web.config"))); domWebConfig.Load(filepath); XmlNode addKey = domWebConfig.SelectSingleNode((XPath.Replace("?", key))); if (addKey == null) { //Response.Write("<script>alert (\"没有找到<add key='" + key + "' value=.../>的配置节\")</script>"); MessageBox.Show("没有找到<add key='" + key + "'>的配置节"); return; } addKey.Attributes["value"].InnerText = strValue; domWebConfig.Save(filepath); MessageBox.Show("数据库连接配置成功","信息提示"); txtConnectionString.Text = connstr; txtConnectionString.Enabled = false; } catch { // MessageBox.Show("在"+Environment.CurrentDirectory + "目录下找不到web.config配置文件","信息提示"); txtConnectionString.Enabled = true; txtConnectionString.Clear(); txtConnectionString.ForeColor = Color.Red; txtConnectionString.Text ="在" + Application.StartupPath + "目录下找不到App.config配置文件"; return; } } private void buttonConn_Click(object sender, EventArgs e) { DataConnectionDialog dialog = new DataConnectionDialog(); //添加数据源列表,可以向窗口中添加自己程序所需要的数据源类型 dialog.DataSources.Add(DataSource.SqlDataSource); dialog.DataSources.Add(DataSource.OdbcDataSource); dialog.SelectedDataSource = DataSource.SqlDataSource; dialog.SelectedDataProvider = DataProvider.SqlDataProvider; //只能够通过DataConnectionDialog类的静态方法Show出对话框 //不同使用dialog.Show()或dialog.ShowDialog()来呈现对话框 if (DataConnectionDialog.Show(dialog, this) == DialogResult.OK) { connstr = dialog.ConnectionString; connstr = "Provider=SQLOLEDB.1;" + connstr; Modify("ConnStr",connstr); } } }} 你这样做很累,可以使用DbConnectionStringBuilder,他对应的有各种数据源提供者的子类 我这个是修改webconfig里的数据库连接串用的。 终于攒了点分可以发帖了,我想问下怎样使用加密狗 根据一个时间获得这一周的时间 数组 求一个只能7位数字的正册表达式 能力有限,数据库程序,用哪个链接呀 Socket通讯问题 ★★★【分享C#源代码(数据工具和C#游戏程序)】★★★ VS2005 下的报表问题 Oledb select uuser,pwd from login where uuser=? and pwd=? Ado.net sqlclient 正则表达式提取网页table DataGridView 组合字段自动更新到数据库 还是数组的问题
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Data.ConnectionUI;
using System.Xml;
namespace DSZQ
{
public partial class DataConn : Form
{
public DataConn()
{
InitializeComponent();
//filepath = Environment.CurrentDirectory;
filepath =Application.StartupPath;
filepath += "//App.config";
}
string filepath;
string connstr;
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="strValue"></param>
public void Modify(string key, string strValue) //两个参数:要修改的键值 和 要修改的新值;
{
string flagstr = strValue;
if (strValue == string.Empty)
{
MessageBox.Show("连接串不能为空!");
return;
}
//string XPath = "/configuration/userInfo/add[@key='?']";
try
{
string XPath = "/configuration/appSettings/add[@key='?']";
XmlDocument domWebConfig = new XmlDocument(); //domWebConfig.Load((HttpContext.Current.Server.MapPath("web.config")));
domWebConfig.Load(filepath);
XmlNode addKey = domWebConfig.SelectSingleNode((XPath.Replace("?", key))); if (addKey == null)
{
//Response.Write("<script>alert (\"没有找到<add key='" + key + "' value=.../>的配置节\")</script>");
MessageBox.Show("没有找到<add key='" + key + "'>的配置节");
return;
}
addKey.Attributes["value"].InnerText = strValue;
domWebConfig.Save(filepath);
MessageBox.Show("数据库连接配置成功","信息提示");
txtConnectionString.Text = connstr;
txtConnectionString.Enabled = false;
}
catch
{
// MessageBox.Show("在"+Environment.CurrentDirectory + "目录下找不到web.config配置文件","信息提示");
txtConnectionString.Enabled = true;
txtConnectionString.Clear();
txtConnectionString.ForeColor = Color.Red;
txtConnectionString.Text ="在" + Application.StartupPath + "目录下找不到App.config配置文件";
return;
} } private void buttonConn_Click(object sender, EventArgs e)
{
DataConnectionDialog dialog = new DataConnectionDialog();
//添加数据源列表,可以向窗口中添加自己程序所需要的数据源类型
dialog.DataSources.Add(DataSource.SqlDataSource);
dialog.DataSources.Add(DataSource.OdbcDataSource); dialog.SelectedDataSource = DataSource.SqlDataSource;
dialog.SelectedDataProvider = DataProvider.SqlDataProvider;
//只能够通过DataConnectionDialog类的静态方法Show出对话框
//不同使用dialog.Show()或dialog.ShowDialog()来呈现对话框
if (DataConnectionDialog.Show(dialog, this) == DialogResult.OK)
{
connstr = dialog.ConnectionString;
connstr = "Provider=SQLOLEDB.1;" + connstr;
Modify("ConnStr",connstr);
}
}
}
}