4 Replies - 465 Views - Last Post: 01 June 2011 - 06:06 AM Rate Topic: -----

#1 jmallory0001  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 31-May 11

C# and SQL: Not sure where to start

Posted 31 May 2011 - 03:54 PM

I need to write an application that will pull data from a database and output to file the records found. I'm using MS Visual Studio 2010. No idea about where to start. The project was just kind of thrown at me because the other programmer is on medical leave. Any and all help will be greatly appreciated.

Thanks
Is This A Good Question/Topic? 0
  • +

Replies To: C# and SQL: Not sure where to start

#2 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: C# and SQL: Not sure where to start

Posted 31 May 2011 - 04:11 PM

dude you are one lucky ducky imo. I have the perfect example application open right now! Lol.


What kind of database are you using?


Here's a little sniff of reading a database
        private void btnReadDatabase_Click(object sender, EventArgs e)
        {
            if (INFOMODE) return;  //ignore this

            if (radMysql.Checked)  // for MySql...
            {
                consoleWrite("reading database from across the web!...");

                MySqlConnection connection = new MySqlConnection(MyConString);
                MySqlCommand command = connection.CreateCommand();
                MySqlDataReader Reader;
                command.CommandText = "select * from " + txtTable.Text;

                MySqlDataAdapter myAdapter = new MySqlDataAdapter(command.CommandText, connection);



                // check if txtTable.Text exists
                bool tableExist = myAdapter.TableExists(txtTable.Text);
                if (tableExist)
                {
                    connection.Open();




                    myDataset = new DataSet();

                    myAdapter.Fill(myDataset, txtTable.Text);


                    bindingSource1.DataSource = myDataset.Tables[0];
                    dataGridView1.DataSource = bindingSource1;

                    consoleWrite("Download Successful");

                    //try
                    //{
                    //    Reader = command.ExecuteReader();
                    //    while (Reader.Read())
                    //    {
                    //        string thisrow = "";
                    //        for (int i = 0; i < Reader.FieldCount; i++)
                    //            thisrow += Reader.GetValue(i).ToString() + ",";
                    //        listBox1.Items.Add(thisrow);
                    //    }
                    //}
                    //catch (Exception exp)
                    //{
                    //    consoleWrite("Error:  " + exp.Message);
                    //}



                    connection.Close();
                }
                else if (!tableExist)
                {
                    consoleWrite("Table does not exist.");
                }

            }
            else // for access database
            {
                //  Set textbox to say "reading..." for 2 seconds
                consoleWrite("reading database table...");

                //  download the database's table into myDataset
                myDataset = GetDataAccessDb(false);

                if (myDataset == null)        // if GetData should fail... it returns a null...  if we have a null, we gotta stop this execution
                    return;


                bindingSource1.DataSource = myDataset.Tables[0];
                dataGridView1.DataSource = bindingSource1;

                consoleWrite("DataBase table '" + txtTable.Text + "' is now visible in text dataGridView.");
                textBox2.Text = "Now Showing the .mdb data!!!!!!!!!!!!!!!!";
            }
        }



I'm on github now, you can browse the project and even clone it: https://github.com/T...tabase/Form1.cs

Plz tell me how easy it is to understand what that app does. I'm preparing a tutorial on this subject.

This post has been edited by NotarySojac: 31 May 2011 - 04:14 PM

Was This Post Helpful? 1
  • +
  • -

#3 jmallory0001  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 31-May 11

Re: C# and SQL: Not sure where to start

Posted 31 May 2011 - 04:17 PM

Thank you very much for the reply. I'll look this over and see if I can get started. Again, thank you.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,516
  • Joined: 23-August 08

Re: C# and SQL: Not sure where to start

Posted 31 May 2011 - 07:09 PM

We have a LOT of tutorials here. And you know what? There a few SQL ones in there too. Start reading; smart people didn't write those just to take up filesystem space.
Was This Post Helpful? 2
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5522
  • View blog
  • Posts: 11,830
  • Joined: 02-June 10

Re: C# and SQL: Not sure where to start

Posted 01 June 2011 - 06:06 AM

View PostJackOfAllTrades, on 31 May 2011 - 08:09 PM, said:

We have a LOT of tutorials here. And you know what? There a few SQL ones in there too. Start reading; smart people didn't write those just to take up filesystem space.


Not only are there database tutorials in the C# tutorial section but there is an entire section devoted strictly to database tutorials.
http://www.dreaminco...base-tutorials/
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1