2 Replies - 1095 Views - Last Post: 16 May 2011 - 05:50 AM Rate Topic: -----

#1 dglnz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-May 11

best way to connect to mysql - bind controls via properties or in code

Posted 16 May 2011 - 05:01 AM

Okay new to C# and lots of questions but databases is were it starts....

okay i have a simple windows form (this being a test bed for my project proper).

what is the best way to connect to MYSQL?
in my test I have a combo box and a label.

In my project the combo box will be used in the same way (record selection and display).

So currently i have the combo box bound via the properties to a table field called names.
When the user changes the name I want data from another table to be displayed in the label.

I cannot figure out how best to do this!!

I've selected the changedindex event method (and read that this has funny results due to when events get fired - ergo strange results).

what complicates things too is that I want the LAST row returned.

here is my code so far....
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'testDataSet.night_visits' table. You can move, or remove it, as needed.
            //this.night_visitsTableAdapter.Fill(this.testDataSet.night_visits);
            // TODO: This line of code loads data into the 'testDataSet.cust_data' table. You can move, or remove it, as needed.
            this.cust_dataTableAdapter.Fill(this.testDataSet.cust_data);

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            label1.Text = what do i put here ???? 
        }
    }
}



Note i'm currently looking at this type of code to give me what i'm wanting...

DataRowCollection test = this.testDataSet.night_visits.Select("select * from night_visits, cust_data where rec_code = acc_code");
                
            label1.Text = test.Last;


I am getting a lot of red wiggly lines on the code above so believe I'm doing something wrong - but what?

any all help gratefully accepted.

dave.

Is This A Good Question/Topic? 0
  • +

Replies To: best way to connect to mysql - bind controls via properties or in code

#2 tlhIn`toq  Icon User is offline

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

Reputation: 5505
  • View blog
  • Posts: 11,808
  • Joined: 02-June 10

Re: best way to connect to mysql - bind controls via properties or in code

Posted 16 May 2011 - 05:36 AM

I would suggest you do a couple of the mySQL tutorials right here on DIC.
There are so many intro to mySQL tutorials here that I'm sure they would give you a full and rich understanding of using it.

http://www.dreaminco...base-tutorials/

as for "lots of red wiggly lines" those are errors the compiler has located as you type. If you hover over them the hothelp will tell you what the errors are.

That also indicates you might be just copy/pasting code from some other project, or the 'net, or a book and the variables don't match those of your project. There is little point in pasting code you don't understand from several sources and hoping to make it all work together.


Debugging tutorial
Debugging tips
Great debugging tips
It still doesn't work, article
Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is offline

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

Reputation: 5505
  • View blog
  • Posts: 11,808
  • Joined: 02-June 10

Re: best way to connect to mysql - bind controls via properties or in code

Posted 16 May 2011 - 05:50 AM

Example of hovering over the offending object to see the problem:

Attached Image

I'm not sure why you would have "lots" of error indications (red wigglies).
When I paste this into a project that has nothing to do with a database there are only two problems with this line - And I had to deliberately place it outside of a method to generate them for this example.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1