using System;
using System.Data;
using System.Data.SqlClient;namespace ConsoleApplication22
{
class Class1
{
static void Main(string[] args)
{
SqlConnection thisConnection=new SqlConnection(@"Data Source=hitler;Integrate Security=SSPI;"
+"Initial Catalog=hotel");
thisConnection.Open();
SqlCommand thisCommand=thisConnection.CreateCommand();
thisCommand.CommandText="SELECT CID,RID from CheckIn ";
SqlDataReader thisReader=thisCommand.ExecuteReader();
while(thisReader.Read())
{
Console.WriteLine("\t{0}\t{1}",thisReader["CID"],thisReader["RID"]);
}
thisReader.Close();
thisConnection.Close(); }
}
}
服务器hitler
服务 SQL server
好像没密码
程序编译没通过...
谁帮忙看看哪里出错了我是要使用hotel 数据库下表CheckIn中的RID.CID项..
using System.Data;
using System.Data.SqlClient;namespace ConsoleApplication22
{
class Class1
{
static void Main(string[] args)
{
SqlConnection thisConnection=new SqlConnection(@"Data Source=hitler;Integrate Security=SSPI;"
+"Initial Catalog=hotel");
thisConnection.Open();
SqlCommand thisCommand=thisConnection.CreateCommand();
thisCommand.CommandText="SELECT CID,RID from CheckIn ";
SqlDataReader thisReader=thisCommand.ExecuteReader();
while(thisReader.Read())
{
Console.WriteLine("\t{0}\t{1}",thisReader["CID"],thisReader["RID"]);
}
thisReader.Close();
thisConnection.Close(); }
}
}
服务器hitler
服务 SQL server
好像没密码
程序编译没通过...
谁帮忙看看哪里出错了我是要使用hotel 数据库下表CheckIn中的RID.CID项..
+"Initial Catalog=hotel");
("Data Source=hitler;Integrated Security=SSPI;"
+"Initial Catalog=hotel");
SqlConnection thisConnection=new SqlConnection("Server=localhost;uid=sa;pwd=;database=hotel");
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace ManagePlam
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class index : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox username;
protected System.Web.UI.WebControls.TextBox password;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Image Image1;
protected System.Web.UI.WebControls.TextBox Vcode;
protected System.Web.UI.WebControls.Label lblShow;
protected System.Web.UI.WebControls.TextBox TextBox3;
private void Button1_Click(object sender, System.EventArgs e)
{
//连接数据库字符串
string ConnectionString = "Server=(local);User id=all;Pwd=all;Database=net_testlog";
string Sql = "SELECT * FROM ALLUSER WHERE username='"+username+"'";
//创建SqlConnection对象
SqlConnection Connection = new SqlConnection(ConnectionString);
//创建SqlCommand对象
SqlCommand Command = new SqlCommand(Sql,Connection);
//打开数据库对CommandText属性赋值
//Command.Connection = Connection;
//Command.CommandText = "SELECT password FROM ALLUSER where username='username'";
//指定命令类型是SQL语句
Command.CommandType = CommandType.Text;
try
{
//打开数据库
//Connection.Open();
//打开数据库连接
Command.Connection.Open();
//Response.Write ("数据库连接成功");
//获取查询结果
object test = Command.ExecuteScalar();
//Response.Write (test);
//执行SQL语句返回DataReader对象
SqlDataReader dr = Command.ExecuteReader();
while(dr.Read())
{
string strpassword = dr["password"].ToString ();//强制转换成STRING型数据
Response.Write (strpassword);
if (password==strpassword)
{
Response.Write ("ok");
}
else
{
string message = ("对不起,您输入的内容有误!");
Response.Redirect ("index.aspx?MSG=" + message );
} }
//关闭 DataReader
dr.Close();
}
catch(SqlException ex)
{
//Response.Write ("数据库连接失败");
//Response.Write (ex);
}
finally
{
//关闭数据库
Connection.Close();
//关闭数据库连接
Command.Connection.Close(); }
}
}
}
为什么啊
{
}
catch(Exception _e)
{
string a=_e.Message;
return new DataTable();
}
finally
{
con.Close();
}
学习中.----------------------------------------------------------------
http://wbweir.anyp.cn/
为神六喝彩,向所有科技工作者致敬!
拒绝日货。