本菜鸟用Visual Studio.net做了一个数据管理方面的界面(非常的简单,就包括登陆、查询、检入和检出),用SQL建立了一个数据库。
可是我不懂如何实现他们之间的连接,一点都不明白啊。
有没有哪位高手能帮我连接好,我把做的界面发给你,能帮我做好吗?
急啊!!
先谢过了!

解决方案 »

  1.   

    using System.Data.SqlClient; DataSet ds=new DataSet("XMLProducts");
    //连接SQL Server数据库SqlConnection conn=new SqlConnection(@"server=glf;uid=sa;pwd=;database=northwind");
    SqlDataAdapter da=new SqlDataAdapter("SELECT * FROM products",conn);//绑定DataGrid控件
    da.Fill(ds,"products");
    ---------------------Sql Server try
    {
    OleDbConnection myConn=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=aa.xls;Extended Properties=Excel 8.0;");
    myConn.Open();
    OleDbDataAdapter thisAdapter= new OleDbDataAdapter("SELECT * FROM [Sheet1$]",myConn);
    OleDbCommandBuilder thisBuilder=new OleDbCommandBuilder(thisAdapter);
    DataSet thisDataSet=new DataSet();
    thisAdapter.Fill(thisDataSet,"ExcelInfo");
    MessageBox.Show(thisDataSet.Tables["ExcelInfo"].Rows[1][1].ToString());
    myConn.Close();
    }
    catch(OleDbException ex)
    {
    MessageBox.Show(ex.Message);
    }
    --------------------Excelusing System.Data;
    using System.Data.OleDb;
    ---------------------------
    OleDbConnection thisConnection=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\D\DevCs\Works2\Person.mdb;");
    thisConnection.Open();
    OleDbCommand thisCommand=thisConnection.CreateCommand(); //
    thisCommand.CommandText="SELECT * FROM Intro";
    OleDbDataReader thisReader=thisCommand.ExecuteReader();
    while(thisReader.Read())
    {
    Console.WriteLine("\t{0}\t{1}",thisReader["ID"],thisReader["TheName"]);
    }
    thisReader.Close();
    thisConnection.Close();---------------------Access
      

  2.   

    1.安装Microsoft ODBC.net。
    2.安装MySQL的ODBC驱动程序。
    2.解决方案管理中添加引用Microsoft.Data.Odbc.dll(1.0.3300)
    3.代码中增加引用
    using Microsoft.Data.Odbc;
    4.编写代码
    string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" + 
    "SERVER=localhost;" +
    "DATABASE=samp_db;" +
    "UID=root;" +
    "PASSWORD=;" +
    "OPTION=3";
    //Connect to MySQL using Connector/ODBC
    OdbcConnection MyConnection = new OdbcConnection(MyConString);    
    MyConnection.Open();
    Console.WriteLine("\n !!! success, connected successfully !!!\n");    
    MyConnection.Close();
     -----------------------MySQL
      

  3.   

    private void btLogin_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
    string connStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db/fnsData.mdb";
    string strSql="select * from users where userID = '" + this.txtUserName.Text.Trim () + "' and userPwd = '"  + this.txtpassword.Text.Trim ()  + "'";
    OleDbConnection conn=new OleDbConnection(connStr);
    OleDbCommand cmd=new OleDbCommand(strSql,conn);
    OleDbDataReader sdr;
    try
    {
    conn.Open ();
    sdr=cmd.ExecuteReader ();
    if(sdr.Read ())
    {
    Response.Write ("<script language='javascript'> alert('登录成功')</script>");
    }
    else
    {
    Response.Write ("<script language='javascript'> alert('请确认输入的账号和密码正确')</script>");
    this.txtUserName.Text ="";
    this.txtUserPwd.Text ="";
    }
    sdr.Close ();
    }
    catch(System.Exception ex)
    {
    throw new Exception (ex.Message );
    }
    finally
    {
    conn.Close ();
    } }
      

  4.   

    this.txtUserPwd.Text =""; 写错是 this.txtpassword.Text ="";这是一个连接access数据库的用户名密码验证的登陆的例子, 数据库是在根目录下面的db目录下面的fnsdata.mdb 包括users表(ID,userID,userPwd)
      

  5.   

    Dim strConn, strSQL As String
                        Dim myConn As OleDbConnection
                        Dim myCommand As OleDbCommand
                        strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(".") & "/db1.mdb"
                        strsql="SELECT * FROM book where type=@type"
                        myConn = New OleDbConnection(strConn)
                        myCommand = New OleDbCommand(strSQL, myConn)
                        myCommand.Parameters.Add("@type",type)
                        myConn.Open()
                        DataList1.DataSource = myCommand.ExecuteReader()
                        DataList1.DataBind()
                        myConn.close()读完了,,,
      

  6.   

    楼上说的对,看看书吧,随便找本。net或C#都有介绍
      

  7.   

    Imports System.Data
    Imports System.Data.SqlClientDim conn as new SqlConnection("Server=Loalhost;uid=sa;pwd=;DataBase=da")
    conn.Open()
    Dim comm as new SqlCommand("Sql",conn)
    comm.ExecuteNonQuery()'对数据库操作开始
      

  8.   

    在VS中再簡單不過了,只要拖入sqlconnection,sqldataadapter控件就差不多可以了。
      

  9.   

    Imports System.Data
    Imports System.Data.SqlClientDim conn as new SqlConnection("Server=Loalhost;uid=sa;pwd=;DataBase=da")
    conn.Open()
    Dim comm as new SqlCommand("Sql",conn)
    comm.ExecuteNonQuery()
      

  10.   

    在VS中再簡單不過了,只要拖入sqlconnection,sqldataadapter控件就差不多可以了。
    --------------------------
    那在C#里就难了?
    有什么区别吗?
      

  11.   

    在csdn里搜索一下,到处都是阿!