private void GetData()
{
    string Constring="Data Source=MISSERVER; Integrated Security=SSPI; Initial        Catalog=Freightage";
    SqlConnection myConn = new SqlConnection(Constring);
    myConn.Open();
    string Selstring ="select * from TBCarBOOK";
    DataSet MyDs=new DataSet();
    SqlDataAdapter myCommand= new SqlDataAdapter (Selstring,Constring);
myCommand.Fill (MyDs);
myConn.Close() ;
dataGrid1.DataSource =MyDs;

 
}

解决方案 »

  1.   

    不知道楼主问题是什么?
    不过楼主代码中有两处:
    1.myConn.Close() ;这句是不需要的
    2.少一句dataGrid1.databind();
      

  2.   

    我到这myConn.Open();
    就错了
      

  3.   

    提示
    未处理的“System.Data.SqlClient.SqlException”类型的异常出现在 system.data.dll 中其他信息:系统错误。
      

  4.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using System.Data;namespace WindowsApplication7
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
             private System.Windows.Forms.Label label1;
    public System.Windows.Forms.DataGrid dataGrid1; /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {

    InitializeComponent();
    GetData();
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    #region Windows Form Designer generated code
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary> private void InitializeComponent()
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    private void GetData()
    {

                     string Constring="Data Source=MISSERVER; Integrated    Security=SSPI;        Initial Catalog=Freightage";
    SqlConnection myConn = new SqlConnection(Constring);
    myConn.Open();
    string Selstring ="select * from TBCarBOOK";
    DataSet MyDs=new DataSet();
    SqlDataAdapter myCommand= new SqlDataAdapter   (Selstring,Constring);
    myCommand.Fill (MyDs);
    myConn.Close() ;
    MessageBox.Show("ok");
    dataGrid1.DataSource =MyDs;

     
    }
    [STAThread]
    static void Main() 
    {

    Application.Run(new Form1());
    }
    }
    }
      

  5.   

    string Constring="Data Source=MISSERVER; Integrated Security=SSPI; Initial        Catalog=Freightage";
    改成
    string Constring="server=localhost;uid=sa;pwd=sa;database=Freightage";
    试试
      

  6.   

    还是不行,我本机沒有装sql2000,MISSERVER是另一台机子的服务器
      

  7.   

    如果是另外机器上的SQL server ,如果两台机器还没有在同一个域上,你会有用系统账户的权限访问数据库么?如果是这样的情况,请采用模拟,要不就采用混合身份验证,
    改成
    string Constring="server=对方机器IP地址;uid=sa;pwd=sa;database=Freightage";
    试试
      

  8.   

    使用客户端工具创建一个别名,
    然后使用这样的连接串
    server=localhost;uid=yyy;pwd=xxx;database=别名
      

  9.   

    greennetboy(我的老婆叫静静) 
    是他说的那样,两台机子在同一域上
    已经可以了.
    谢谢大家