关于ADO.NET-创建一个登陆窗口 连接SQLServer2000
2007-10-18 17:23
435 查看
这里主要用到了System.Data.Sqlclient对象
连接首先创建一个Connection连接
然后使用数据命令
今天作的例子很简单 没有用复杂的数据命令
代码发在这里
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace ObjectTest
{
public partial class Form1 : Form
{
public SqlConnection Connect()
{
//建立数据库连接
SqlConnection SqlDbConnection1 = new SqlConnection("Server=localhost;Database=sqldb_test;uid=sa;pwd=rickey");
//SqlDbConnection1.ConnectionString = "Server=localhost;Database=sqldb_test;uid=;pwd=";
SqlDbConnection1.Open();
return SqlDbConnection1;
}
public Form1()
{
InitializeComponent();
this.Connect();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
//使用数据命令 操作数据库 对数据库进行查询
String u_name = textBox1.Text;
String u_password = textBox2.Text;
SqlConnection SqlDbConnection = Connect();
String sqlstr = "select * from user_check where u_name = '" + u_name + "' and u_password = '" + u_password + "'";
SqlCommand scd = new SqlCommand(sqlstr, SqlDbConnection);
if (scd.ExecuteScalar() == null)
{
MessageBox.Show("用户名或密码错误");
textBox1.Text = "";
textBox2.Text = "";
textBox1.Focus();
}
else
{
MessageBox.Show("登陆成功");
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox1.Focus();
}
}
}
很高兴 连接到了数据库
好象以前学其他开发平台的时候就觉得连接上了数据库
就没有什么再难的了
其实并不是这样的
以后要学的细节的东西还很多
要加油!!!
连接首先创建一个Connection连接
然后使用数据命令
今天作的例子很简单 没有用复杂的数据命令
代码发在这里
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace ObjectTest
{
public partial class Form1 : Form
{
public SqlConnection Connect()
{
//建立数据库连接
SqlConnection SqlDbConnection1 = new SqlConnection("Server=localhost;Database=sqldb_test;uid=sa;pwd=rickey");
//SqlDbConnection1.ConnectionString = "Server=localhost;Database=sqldb_test;uid=;pwd=";
SqlDbConnection1.Open();
return SqlDbConnection1;
}
public Form1()
{
InitializeComponent();
this.Connect();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
//使用数据命令 操作数据库 对数据库进行查询
String u_name = textBox1.Text;
String u_password = textBox2.Text;
SqlConnection SqlDbConnection = Connect();
String sqlstr = "select * from user_check where u_name = '" + u_name + "' and u_password = '" + u_password + "'";
SqlCommand scd = new SqlCommand(sqlstr, SqlDbConnection);
if (scd.ExecuteScalar() == null)
{
MessageBox.Show("用户名或密码错误");
textBox1.Text = "";
textBox2.Text = "";
textBox1.Focus();
}
else
{
MessageBox.Show("登陆成功");
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox1.Focus();
}
}
}
很高兴 连接到了数据库
好象以前学其他开发平台的时候就觉得连接上了数据库
就没有什么再难的了
其实并不是这样的
以后要学的细节的东西还很多
要加油!!!
相关文章推荐
- 关于ADO.NET,只须一个连接,一条SQL语句,轻松实现增删改查
- Synchronization Services for ADO.NET - 创建一个偶然连接数据库系统。(数据同步系统)
- ADO.NET笔记——使用Connection连接数据库,使用Command对象的ExecuteReader()方法创建DataReader对象返回多行数据
- 给vs2010中内置sqlserver2008添加了一个添加了一个管理界面后ADO.NET FrameWork Entity连接不上sqlserver2008
- 关于netkeep连不了网的一个问题(点击连接互联网后按钮变灰色)
- ADO.Net实现非连接的简单分页方法(DataAdapter.Fill重载中的一个).
- VS2010/VS2013项目创建 ADO.NET连接mysql/sql server详细步骤
- #菜鸟新手EclipseJavaEE&MySQL&Tomcat#关于一个Eclipse中登陆界面通过连接MySQL数据库进行验证的小体验(感谢qq群友引燃的解答让我解决这个小问题)
- [Ado.Net]关于数据库连接Dispose和Close区别
- ado.net连接sql server 2000数据库一定要连网(连一个路由也可以)的问题
- 关于Cocoa的窗口创建调用-一个nib包含两个窗口
- VS 连接MySQL,创建ADO.NET实体集,报错:StrongTypingException: 表“TableDetails”中列“IsPrimaryKey”的值为 DBNull。
- 用ASP.NET连接数据库写的一个登陆注册界面
- 关于ADO.NET连接SQL一些方法
- 关于怎么C#控制台窗口中怎么创建连接查询数据库操作
- 关于Cocoa的窗口创建调用-一个nib包含两个窗口
- c# sqlite 数据库加密2010-05-29 10:55用了ADO.NET 2.0 SQLite Data Provider 这样可以直接利用它来创建一个加密的sqlite数据库。
- ado.net实现一个简单的登陆
- 只允许创建一个实例的VB.NET窗口
- ADO.Net实现非连接的简单分页方法(DataAdapter.Fill重载中的一个).