Some Database Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • firejunior88
    New Member
    • Oct 2007
    • 3

    Some Database Help

    Hello, my first post:

    Sorry if this is a noob question.

    I have a problem. I have added a database to my project in Visual Studio 2005. I created my tables, and threw in some data to do some tests. Some of my screens have DataGridViews to show the data that is needed.

    1. How do I go about connecting to thise database in my project?
    2. How do I execute queries to fill the GridViews?
    3. When I go to create the .exe file, will this database be built into the file?

    Thanks for the help.
  • Lokean
    New Member
    • Apr 2007
    • 71

    #2
    Originally posted by firejunior88
    Hello, my first post:

    Sorry if this is a noob question.

    I have a problem. I have added a database to my project in Visual Studio 2005. I created my tables, and threw in some data to do some tests. Some of my screens have DataGridViews to show the data that is needed.

    1. How do I go about connecting to thise database in my project?
    2. How do I execute queries to fill the GridViews?
    3. When I go to create the .exe file, will this database be built into the file?

    Thanks for the help.
    1)Visual studio creates connection strings for you. Click on Data>> Add new datasource, and follow the prompts.

    2)once you create the Visual studio datasets, the .fill and the .getdata commands will do the work for you. you just feed the parameters you need into the .fill command.

    EXAMPLE.


    Code:
      Dim a As New LMDataSetTableAdapters.dpGetSomeDataTableAdapter
    
     a.Fill(Me.LMDataSet.dpGetSomeData, "5/1/2007", "6/1/2007", "3", Nothing, "9999", "Widgets")
    3)The connection to the database will be built in.

    Comment

    • firejunior88
      New Member
      • Oct 2007
      • 3

      #3
      Originally posted by Lokean
      1)Visual studio creates connection strings for you. Click on Data>> Add new datasource, and follow the prompts.

      2)once you create the Visual studio datasets, the .fill and the .getdata commands will do the work for you. you just feed the parameters you need into the .fill command.

      EXAMPLE.


      Code:
        Dim a As New LMDataSetTableAdapters.dpGetSomeDataTableAdapter
      
       a.Fill(Me.LMDataSet.dpGetSomeData, "5/1/2007", "6/1/2007", "3", Nothing, "9999", "Widgets")
      3)The connection to the database will be built in.
      Can you give me an example of #1? Like how to connect to it through code and executing a query through code?

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Your database is probably an SQL database and no, i don't believe it travels with the .exe (I might be wrong on this, but I don't think it does)

        You'll gain more understanding of it if you do it through code and not the designer.
        Have a look at this article:

        Comment

        • firejunior88
          New Member
          • Oct 2007
          • 3

          #5
          Originally posted by Plater
          Your database is probably an SQL database and no, i don't believe it travels with the .exe (I might be wrong on this, but I don't think it does)

          You'll gain more understanding of it if you do it through code and not the designer.
          Have a look at this article:
          http://www.thescripts.com/forum/thread635615.html
          That article did explain and help me quite a bit. But it did not show me something, how do execute a "SELECT" statement, and store the results into a datatable. I want it in a datatable so I can manipulate and display the data the way I want it. Its easier for me that way. So any help on that would be helpful.

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Here's a little snippit I was using in my code as an example:
            Code:
            public static DataTable GetParts()
            {
            DataTable retval = new DataTable();
            retval.TableName = "Part";
            _lasterror = "";
            string myq = "";
            init();
            
            try
            {
                myq = "SELECT ";
                myq += " * ";
                myq += " FROM ";
                myq += " Parts";
                myq += " ORDER BY Parts.PartID ASC, Parts.Name ASC ";
                myq += ";";
            
            //dbcon is my database connection which is already opened
                SqlDataAdapter dba = new SqlDataAdapter(myq, dbcon);
                dba.Fill(retval);
            }
            catch (Exception ee)
            {
                ReportError("GetParts", ee);
                retval = null;
            }
            return retval;
            }

            Comment

            Working...