请.NET高手帮忙看看代码

来源:百度知道 编辑:UC知道 时间:2024/05/31 23:40:55
这是我写的代码 运行没错 .但是还是没跟数据库连上 请问是什么原因.
好象完全没起作用
using System;using System.Collections;usingSystem.Configuration;usingSystem.gSystem.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)

{

string strConn = ("Server=; Database=itzc; uid=sa;pwd=sa;");
string strCmd = ("select count(*) from Staff_login where (S_ID == ' " + S_ID.Text + " ' and Sl_pwd= ' " + Sl_pwd.Text + " '");
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = strConn;
SqlCommand myCommand = new SqlCommand(strCmd, myConnection);

我比较懒,不想看代码,呵呵,建议单步调试
只看了Button1_Click中的代码
1、服务器地址写上
2、string strCmd = ("select count(*) from Staff_login where (S_ID == ' " + S_ID.Text + " ' and Sl_pwd= ' " + Sl_pwd.Text + " '"); 改成
string strCmd = ("select count(*) from Staff_login where S_ID = '" + S_ID.Text + "' and Sl_pwd= '" + Sl_pwd.Text + " '");
即:
a:“S_ID ==”改成“S_ID =” 一个等号
b: ' "单引号和双引号之间不要有空格
c: S_ID前多了半个(

都是细节问题,多用单步调式

string strConn = ("Server=; Database=itzc; uid=sa;pwd=sa;");
这个好象没有写服务器地址吧Server=.;

在你的报错的那些条件里全都加上return,表示程序到这一步就不执行下面的代码了、。

明白否?