C# and database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prokopis
    New Member
    • Nov 2007
    • 30

    C# and database

    i have a small problem.
    am writting a program in c# with sql server
    this that i want is to take a particular row from the database and put all the fields of that row to a 2d array
    example database
    ID name surname
    1 prokopis prokopis
    2 marios marios
    i have connect the program with the database but the problem is that i don't know how to insert the specific row to the array.
    the code that i use until now
    SqlCommand queryDiagnosis = new SqlCommand("SEL ECT * from [Diagnosis] WHERE [IDD] = " + rowaction[0], dataConnectionD iagnosis);
    SqlDataAdapter dataAdapter = new SqlDataAdapter( queryDiagnosis) ;
    dataAdapter.Fil l(datasetDiagno sis, "[Diagnosis]");
    SqlDataReader myreader = queryDiagnosis. ExecuteReader() ;
    int[ , ] tablelist = new int[rownumber, columsize];

    for exampe i want the user with id egual 2 all the data to be insert on the array tablelist.could someone help me pls???
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    This post may help:
    ADO or ADOn't, binding data to an array?

    Comment

    • prokopis
      New Member
      • Nov 2007
      • 30

      #3
      thanks you for the link that you gave me.i might even chang it to a datatable too

      Comment

      • balabaster
        Recognized Expert Contributor
        • Mar 2007
        • 798

        #4
        Originally posted by prokopis
        thanks you for the link that you gave me.i might even chang it to a datatable too
        VB
        Code:
        Dim fileName As String = "C:\MyDB.accdb"
        Dim tableName As String = "MyTable"
        Dim rowToExtract As Integer = 2
        Dim sConStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & fileName & ";Persist Security Info=False;"
        Dim oDA As New OleDbDataAdapter("Select * From " & tableName, sConStr)
        Dim oDS As New DataSet("MyDataSet")
        oDA.Fill(oDS, "MyTable")
        Dim oDT As DataTable = oDS.Tables("MyTable")
        Dim Data As Array = oDT.Rows(rowToExtract).ItemArray
        C#
        Code:
        string fileName = "C:\\MyDB.accdb";
        string tableName = "MyTable";
        int rowToExtract = 2;
        string sConStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Persist Security Info=False;";
        OleDbDataAdapter oDA = new OleDbDataAdapter("Select * From "+ tableName, sConStr);
        DataSet oDS = new DataSet("MyDataSet");
        oDA.Fill(oDS, "MyTable");
        DataTable oDT = oDS.Tables["MyTable"];
        Array Data = oDT.Rows[rowToExtract].ItemArray;

        Comment

        Working...