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;
using System.Data.SqlClient; //连接数据库的头文件namespace WinFormSQL_exe
{
/// <summary>
///连接数据库流程:
///1.创建连接字符串: String conn = "Data Source=.;Initial Catalog=winformSQL;Integrated Security=True";
///2.创建连接对象 : SqlConnection connect = new SqlConnection(conn);
///3.创建sql语句 :string sql="";
///4.创建SqlCommand对象: SqlCommand command = new SqlCommand(Sql, connect);
///5.打开数据库连接 connet.open()
///6.执行命令:int num = Convert.ToInt32(command.ExecuteScalar());
///7.关闭数据库:
/// </summary>
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String name = this.textBox1.Text;
String password = this.textBox2.Text;
//获得数据库连接字符串Data Source=.;Initial Catalog=tempdb;Integrated Security=True
String conn = "Data Source=.;Initial Catalog=tempdb;Integrated Security=True";
//创建SqlConnection
SqlConnection connect = new SqlConnection(conn);
String Sql = String.Format("Select * form tempdb Londing where usemer ='{0}'and password='{1}'", name, password);
//创建SqlCommand对象
SqlCommand command = new SqlCommand(Sql, connect);
connect.Open();
int num = Convert.ToInt32(command.ExecuteScalar());
try
{
if (num > 0)
{
MessageBox.Show("登陆成功!");
}
else
{
MessageBox.Show("账户或密码错误!");
}
}
catch(Exception ex)
{
MessageBox.Show("异常!"+ex); }
finally
{
connect.Close();
}
}
}
}
这些是我从视频上学习的,但是在点击登录的时候是错的,总是提示说form或者是*号附近有错误,具体我不知道是什么原因,望大神们指点一下。。c#
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient; //连接数据库的头文件namespace WinFormSQL_exe
{
/// <summary>
///连接数据库流程:
///1.创建连接字符串: String conn = "Data Source=.;Initial Catalog=winformSQL;Integrated Security=True";
///2.创建连接对象 : SqlConnection connect = new SqlConnection(conn);
///3.创建sql语句 :string sql="";
///4.创建SqlCommand对象: SqlCommand command = new SqlCommand(Sql, connect);
///5.打开数据库连接 connet.open()
///6.执行命令:int num = Convert.ToInt32(command.ExecuteScalar());
///7.关闭数据库:
/// </summary>
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String name = this.textBox1.Text;
String password = this.textBox2.Text;
//获得数据库连接字符串Data Source=.;Initial Catalog=tempdb;Integrated Security=True
String conn = "Data Source=.;Initial Catalog=tempdb;Integrated Security=True";
//创建SqlConnection
SqlConnection connect = new SqlConnection(conn);
String Sql = String.Format("Select * form tempdb Londing where usemer ='{0}'and password='{1}'", name, password);
//创建SqlCommand对象
SqlCommand command = new SqlCommand(Sql, connect);
connect.Open();
int num = Convert.ToInt32(command.ExecuteScalar());
try
{
if (num > 0)
{
MessageBox.Show("登陆成功!");
}
else
{
MessageBox.Show("账户或密码错误!");
}
}
catch(Exception ex)
{
MessageBox.Show("异常!"+ex); }
finally
{
connect.Close();
}
}
}
}
这些是我从视频上学习的,但是在点击登录的时候是错的,总是提示说form或者是*号附近有错误,具体我不知道是什么原因,望大神们指点一下。。c#
解决方案 »
- C#中怎么定义一个数组初始化为空,然后动态往里面加入数据
- WebBrowser有图片,不能完成Complete怎么办?
- (高分)为什么在我的程序里用不了用不了EasingFunctionBase??
- 委托的问题?
- C#如何获取DNS服务器地址?????
- C# winfrom关于对Excel查询
- 奇怪,我的MouseDown事件没用了??
- 一个生成HTML文件的问题,,急!!!!!
- AXShockwave flash object 可以和c#实现数据传送吗?
- C#中打开Word出错:被呼叫方拒绝接收方呼叫--急,在线等待高手
- 委托跟事件的问题,高手们求指教..
- 不用枚举怎么知道USB插入在某个端口上
(1)from
(2)and前加一个空格
(3)usemer这个拼写确认是否正确
(4)password加上括号:[password]
如果是,你改成[tempdb].[dbo].[Londing]