VB 2005 and SQL 2005.

Soldato
Joined
30 Jul 2004
Posts
10,572
Location
East Sussex, UK
Afternoon guys.

I'm busy developing a program, databesed. That will allow me to keep track of all repairs, customer names ect for a shop. Now, I am usinf Visual Basic 2005 Express Edition and Microsoft SQL Server 2005 to do this. However, I am running into problems, as expect. Since I am very new to these two bits of software.

Now, let me give a small example of what I am trying to achive here. The form1 will hold almost everything the app has to offer. The customer's details, repair details ect. Now, what I want to be able to do is have a textbox where I can type a job number, cell number or any relavent info, based on the customer. Then i want to software to find the infomation in the data base and display the relevent info in the relevent boxes.

Possible?

Next question..to simpliy things..could I have the above boxes as said above just to enter details. Then, when I search for customer it would just open up a box with relevent details..or is that harder to do?

Any help would be great!!

Thanks all!
 
You can do that yes, but what you would need to do is build the SQL depending if the TextBox, ComboBox has a value entered/selected. But you would need to have something extra to handle a situation where more than 1 record is found. If one record is found great, populate the relevant controls. If there is more than one record then you would need maybe an extra form with a DataGridView maybe? showing what records have been found, then you can select the one you want, press ok and then it fills the boxes.

To build the SQL you could do something like this:
Code:
Dim strSQL As String = "SELECT col1, col2, col3 FROM Table1 WHERE 1 = 1 "
This would return all records in the instance where no search data was entered.

If data is entered then we extend strSQL like this:
Code:
If (Me.txtSomething.Text <> "")Then
    strSQL += "AND col1 = '" + Me.txtSomething.Text + "' "
End If
Hope this helps.

If it makes no sense add me on MSN and I will talk you through it more there.

TrUz
 
Here is a quick example of how you could go about it. I do not have VB installed in here so it is C# but you should get the idea.
Code:
        private void button1_Click(object sender, EventArgs e)
        {
            string strSQL = "SELECT col1, col2, col3 FROM Table1 WHERE 1 = 1 ";

            if (this.textBox1.Text != "")
                strSQL += "AND col1 = '" + this.textBox1.Text + "' ";

            if (this.textBox2.Text != "")
                strSQL += "AND col1 = '" + this.textBox2.Text + "' ";

            if (this.textBox3.Text != "")
                strSQL += "AND col1 = '" + this.textBox3.Text + "' ";

            using (SqlConnection cnn = new SqlConnection(""))
            {
                cnn.Open();

                using (SqlCommand cmd = new SqlCommand(strSQL, cnn))
                {
                    cmd.CommandType = CommandType.Text;

                    SqlDataReader reader = cmd.ExecuteReader();

                    int count = 0;

                    while (reader.Read())
                    {
                        count++;

                        // Fill the controls with the first record...

                        // If the count is greater than 1 show a messagebox or something saying more than 1
                        // record found, would you like to see these results etc...
                        if (count > 1)
                        {
                            DialogResult result = MessageBox.Show("More than 1 record was found etc...", "Program", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                            if (result == DialogResult.Yes)
                            {
                                // Do some sexy stuff.
                            }
                        }
                    }

                    cmd.Dispose();
                }

                cnn.Close();
            }
        }
TrUz
 
MNuTz: No, it's just too messy and not what I really want. Also I am wanting to get into programming, so this is a great way to start.

TrUz: That makes a little sense to me pal. Will give it a try. Thanks a lot for the info. Now, I would have the code in the event handler of the button I want as a search button, correct?

The DataGridView, I haven't used before, however sounds like a way to do it if I have two of the same entries.

I will add you to MSN. Many thanks pal, really appericate it! :cool:
 
Ice On Fire said:
MNuTz: No, it's just too messy and not what I really want. Also I am wanting to get into programming, so this is a great way to start.

Fair enough, i understand the programming but too. Im in the same boat at the moment, trying to learn VB and then VB.net but its finding something to programme thats the problem for me.
 
Start off with a data based program, then an rss feeder like I am doing. There is a lot of help on the MSDN site. :)
 
Ice On Fire said:
What program do I use for that, is it easier?

Its not easier, but conceptually they're both pretty similar.

You can get the C# Express Edition from the same site you got VB.

Having learnt VB and then C# I have never looked back to VB.

As for your project, I would suggest perhaps an MDI form with a search textbox in the toolbar and a new record button.

You can then put text in the search textbox to find records (perhaps opening a new form with a datagridview for multiple hits and allowing you to chose one) or click the new record button for a new record.

This way you can use the same form for both new and existing records (saves code) - but by overloading the constructor you can specify if its a new record or not (this last bit may be somewhat over your head - but you'll soon learn ;) )
 
SiriusB said:
Don't bother with VB. Just learn .NET. Better yet, sod VB altogether and learn C#.NET.
But he's already learning VB.NET :confused:

There's a time and a place for C# zealotry, people. He's asked for help with a VB.NET project, so preaching about the merits of C# isn't that helpful. :p

After all, they're almost identical languages.
 
Thanks, Inquisitor.

Will be sticking to VB.Net C++. As I started it two weeks ago, so won't give up now.

As for the project..well I am seriously stuck with it now..:(
 
Ice On Fire said:
Thanks, Inquisitor.

Will be sticking to VB.Net C++. As I started it two weeks ago, so won't give up now.

As for the project..well I am seriously stuck with it now..:(

VB.NET C++?? Which language are you learning? ;)

My advice would be to borrow a decent beginners book and check out the VB Express videos (iirc they're linked to from the MS site).

The reason most people are suggesting C# over VB is that C# is much more future proof, as it was designed for the .NET framework rather than carried over into it like VB .NET. Certainly having learnt both to a degree, I'd take C# any day of the week because it is, imo, far better structured and teaches one better habits.
 
VB.Net has been rebuilt from the ground up and is a totally new language, just like C#.

The only thing it has in common with VB6 is the same thing that C# has in common with C++, ie. its syntax.

Once one language is learned, to swap languages one simply has to apply the new syntax. I went from C++ to VB6 to VB.Net to C# without any problems at all.

As for teaching better habits, that depends if you're from a VB6 background or a C# background. I've seen some truly awful things in C# (by an ex VB6 developer) as well as VB.Net coded well (by an ex C++ developer)...just using a language is different to using it well - and there's nothing inherent in either language which is "bad coding practice" - there's only bad coders.

:)
 
What are you trying to pull out of the database ?

GridView's are good for when you want to display a few rows of the same data, but they are not good for when you want to display one record of data.

I presume from reading your project description that you want to do something like:

1) Enter a Customer Name / Post Code / Reference Number

2) A list of possible's is displayed if there is more than one record in the result set. If there is only one record found, then just display the information.

3) Format the way the data is displayed.

That is a really high level view of the program. I dont know if you have any what you want to do written down, but it might be worth just listing out a few of the major "features" you want your software to have.

It sounds like a pretty good project to start on though.

What are you currently stuck on ?

Andrew
 
Hi Andrew,

Well, what I want to do is have a few boxes on a single form. Each box must have data. So, one box for first name, next box for second name and so forth. Then I want three buttons, search, add, edit, delete. (Sorry, four buttons)

Is this a dificult thing to do?
 
Nope thats a piece of cake, but thats only a very small part of the application as you'll need more than one form.

I'll paste a few screenshots from a very simple app i wrote (in C# & SQL) when I was teaching myself C#, as i expect it would be broadly similar to what you wanna do.
 
Back
Top Bottom