我的主界面: public class MainFrm : System.Windows.Forms.Form
{    private DataSet ds=new DataSet ();
private LinkDataBase link=new LinkDataBase();
private string sendTableName="权限清单";
private string sendStrSQL; private System.ComponentModel.Container components = null; public MainFrm()
{

InitializeComponent();

            

}
static void Main()
{
//整个程序启动时先显示登录框,登录成功再显示主界面
LoginFrm login=new LoginFrm ();
login.ShowDialog();
    if(LoginFrm.blCanLogin==true)
{
Application.Run(new MainFrm());

}
}
      }
我的数据库连接:
using System;
using System.Data;
using System.Data.SqlClient;
namespace 进销存管理系统
{

public class LinkDataBase
{   
private string strSQL;
//与SQLServer的连接字符串的设置
private string connectionString="workstation id=localhost;Integrated Security=SSPI;database=jxcglxt";
//与数据库的连接
        private SqlConnection  myConnection;
private SqlCommandBuilder  myCommandBuilder;
private DataSet ds=new DataSet ();
private SqlDataAdapter da; public LinkDataBase()
{

}
       
//操作脱机数据库(创建了该类的实例时直接使用)
//根据输入的SQL语句检索数据库数据
public DataSet SelectDataBase(string tempStrSQL,string tempTableName)
{
this.strSQL=tempStrSQL;
            this.myConnection=new SqlConnection (connectionString);
this.myConnection.Open();
this.da=new SqlDataAdapter (this.strSQL,this.myConnection);
this.ds.Clear();
this.da.Fill(ds,tempTableName);
return ds;
//this.myConnection.Close();
} //数据库数据更新(传DataSet和DataTable的对象)
public DataSet UpdateDataBase(DataSet changedDataSet,string tableName)
{
this.myConnection=new SqlConnection (connectionString);
this.myConnection.Open();
this.da=new SqlDataAdapter (this.strSQL,myConnection);
this.myCommandBuilder=new SqlCommandBuilder(da);
this.da.Update(changedDataSet,tableName);
return changedDataSet; //返回更新了的数据库表
//this.myConnection.Close();
}
        
//直接操作数据库(未创建该类的实例时直接使用)
//检索数据库数据(传字符串,直接操作数据库)
public DataTable SelectDataBase(string tempStrSQL)
{
this.myConnection = new SqlConnection(connectionString);
this.myConnection.Open();
DataSet tempDataSet = new DataSet();
this.da = new SqlDataAdapter(tempStrSQL,this.myConnection);
this.da.Fill(tempDataSet);
return tempDataSet.Tables[0];
//this.myConnection.Close();
} //数据库数据更新(传字符串,直接操作数据库)
public int UpdateDataBase(string tempStrSQL)
{
this.myConnection = new SqlConnection(connectionString);
//使用Command之前一定要先打开连接,后关闭连接,而DataAdapter则会自动打开关闭连接
myConnection.Open();
SqlCommand tempSqlCommand = new SqlCommand(tempStrSQL,this.myConnection);
int intNumber = tempSqlCommand.ExecuteNonQuery();//返回数据库中影响的行数
myConnection.Close();
return intNumber;
}
}
}
主界面的程序我只是把主要的部分贴出来了
我每次运行,登录框出来了,输入完密码和用户,点击登录按钮,主界面就不出来,在数据库连接程序的this.da.Fill(ds,tempTableName);出现错误
“System.Data.SqlClient.SqlException”类型的异常出现在 system.data.dll 中。其他信息: 系统错误。
麻烦哪位帮我看看是哪里出错了,十分感谢

解决方案 »

  1.   

    看来是你的SQL语句的问题,把你的查询的SQL语句帖出来
      

  2.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace 进销存管理系统
    {

    public class MainFrm : System.Windows.Forms.Form
    {    private DataSet ds=new DataSet ();
    private LinkDataBase link=new LinkDataBase();
    private string sendTableName="权限清单";
    private string sendStrSQL; private System.Windows.Forms.StatusBar statusBar1;
    private System.Windows.Forms.MainMenu mainMenu1;
    private System.Windows.Forms.MenuItem menuItem1;
    private System.Windows.Forms.MenuItem menuItem5;
    private System.Windows.Forms.MenuItem menuItem7;
    private System.Windows.Forms.MenuItem menuItem9;
    private System.Windows.Forms.MenuItem menuItem11;
    private System.Windows.Forms.MenuItem menuItem13;
    private System.Windows.Forms.StatusBarPanel statusBarPanel1;
    private System.Windows.Forms.StatusBarPanel statusBarPanel2;
    private System.Windows.Forms.MenuItem mnuWareDataManage;
    private System.Windows.Forms.MenuItem mnuProviderDataManage;
    private System.Windows.Forms.MenuItem mnuClientDataManage;
    private System.Windows.Forms.MenuItem mnuStockTable;
    private System.Windows.Forms.MenuItem mnuSellTable;
    private System.Windows.Forms.MenuItem mnuStorageSearch;
    private System.Windows.Forms.MenuItem mnuPopedomManage; private System.ComponentModel.Container components = null; public MainFrm()
    {

    InitializeComponent();

                

    }
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
     
    static void Main()
    {
    //整个程序启动时先显示登录框,登录成功再显示主界面
    LoginFrm login=new LoginFrm ();
    login.ShowDialog();
        if(LoginFrm.blCanLogin==true)
    {
    Application.Run(new MainFrm());

    }
    }
             //创建窗体时,通过登录用户的名称和权限,设置可以访问的功能
    private void MainFrm_Load(object sender, System.EventArgs e)
    {
        this.statusBarPanel2.Text="当前用户" + LoginFrm.strUser + "所属部门" + LoginFrm.strDepartment;
    //通过用户编号查询权限清单,说明用户具有操作哪些窗体的权限 this.sendStrSQL="select 权限名称 from 权限清单 where 用户编号=' " + LoginFrm.strUser + "'";
    this.ds=this.link.SelectDataBase(sendStrSQL,sendTableName); //系统管理用户为特殊权限用户,始终拥有所有权利
    if(LoginFrm.strDepartment=="系统管理")
    {
    this.mnuWareDataManage.Enabled=true;
    this.mnuProviderDataManage.Enabled=true;
    this.mnuClientDataManage.Enabled=true;
    this.mnuStockTable.Enabled=true;
    this.mnuSellTable.Enabled=true;
    this.mnuStorageSearch.Enabled=true;
    this.mnuPopedomManage.Enabled=true;
    }
    else
    {
    //根据从数据库中检索到的用户权限来设置哪些菜单有使用的权利 for(int intCounter=0;intCounter<this.ds.Tables[0].Rows.Count;intCounter++)
    {
    if(ds.Tables[0].Rows[intCounter][0].ToString().Trim()=="商品资料维护")
    this.mnuWareDataManage.Enabled=true;
    //continue;
    if(ds.Tables[0].Rows[intCounter][0].ToString().Trim()=="供应商资料维护")
    this.mnuProviderDataManage.Enabled=true;
    //continue;
    if(ds.Tables[0].Rows[intCounter][0].ToString().Trim()=="客户资料维护")
    this.mnuClientDataManage.Enabled=true;
    //continue;
    if(ds.Tables[0].Rows[intCounter][0].ToString().Trim()=="进货单")
    this.mnuStockTable.Enabled=true;
    //continue;
    if(ds.Tables[0].Rows[intCounter][0].ToString().Trim()=="销售单")
    this.mnuSellTable.Enabled=true;
    //continue;
    if(ds.Tables[0].Rows[intCounter][0].ToString().Trim()=="库存查询")
    this.mnuStorageSearch.Enabled=true;
    //continue;
    if(ds.Tables[0].Rows[intCounter][0].ToString().Trim()=="权限管理")
    this.mnuPopedomManage.Enabled=true;
    //continue;
    }
    }
    } //查询一个子窗体是否存在
    private bool checkChildFrmExist(string childFrmName)
    {
    foreach(Form childFrm in this.MdiChildren)
    {
    //用子窗体的名字进行判断,如果存在就将它激活
    if(childFrm.Name==childFrmName)
    {
    if(childFrm.WindowState==FormWindowState.Minimized)
    childFrm.WindowState=FormWindowState.Normal;

    childFrm.Activate();
    return true;

    }

    }
               return false;
    }
            
    //显示商品信息维护窗体
    private void mnuWareDataManage_Click(object sender, System.EventArgs e)
    {     
    //如果窗体存在就返回
        if(this.checkChildFrmExist("WareDataManage")==true)
    return; //如果该窗体不存在就生成一个商品信息维护窗体
    WareDataManage newFrm=new WareDataManage(true);
    this.MdiParent=this;
    newFrm.Show();
    }
            
    //显示供应商信息维护窗体
    private void mnuProviderDataManage_Click(object sender, System.EventArgs e)
    {
        if(this.checkChildFrmExist("ProviderDataManage")==true)
    return;
    ProviderDataManage newFrm=new ProviderDataManage (true);
    this.MdiParent=this;
    newFrm.Show(); }
            
    //显示客户信息维护窗体
    private void mnuClientDataManage_Click(object sender, System.EventArgs e)
    {
        if(this.checkChildFrmExist("ClientDataManage")==true)
    return;
    ClientDataManage newFrm=new ClientDataManage (true);
    this.MdiParent=this;
    newFrm.Show();
    }
            
    //显示进货单窗体
    private void mnuStockTable_Click(object sender, System.EventArgs e)
    {
        if(this.checkChildFrmExist("StockTable")==true)
    return;
    StockTable  newFrm=new StockTable ();
    this.MdiParent=this;
    newFrm.Show();
    }
            
    //显示销售单窗体
    private void mnuSellTable_Click(object sender, System.EventArgs e)
    {
       if(this.checkChildFrmExist("SellTable")==true)
       return;
    SellTable newFrm=new SellTable ();
    this.MdiParent=this;
    newFrm.Show();
    }
            
    //显示库存查询窗体
    private void mnuStorageSearch_Click(object sender, System.EventArgs e)
    {
        if(this.checkChildFrmExist("StorageSearch")==true)
    return;
                 StorageSearch newFrm=new StorageSearch ();
    this.MdiParent=this;
    newFrm.Show();
    }
             //显示权限管理窗体
    private void mnuPopedomManage_Click(object sender, System.EventArgs e)
    {
       if(this.checkChildFrmExist("PopedomManage")==true)
       return;
               PopedomManage newFrm=new PopedomManage ();
    this.MdiParent=this;
    newFrm.Show();
    }
            
    //退出窗体,先询问用户是否退出
    private void menuItem13_Click(object sender, System.EventArgs e)
    {
       if(MessageBox.Show("确实要退出系统吗?","询问",MessageBoxButtons.YesNo)==DialogResult.Yes)
       this.Close();
    }
            
         
    }
    }
      

  3.   

    用户编号=' " + LoginFrm.strUser + "'"
    用户编号是什么字段的
      

  4.   

    Fill出错一般来说是你的数据库操作方面的问题,比较明显的就是SQL语句的问题
      

  5.   

    弱弱说下,这个这样写对吗? 
    private string connectionString="workstation id=localhost;Integrated Security=SSPI;database=jxcglxt";我平常都是写成: "user id=sa;password=;integrated security=SSPI;initial catalog=jxcglxt;data source=(local)"