1 Replies - 365 Views - Last Post: 27 November 2012 - 08:28 AM Rate Topic: -----

#1 Lightor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-November 12

Question on how to use SQL in C#

Posted 27 November 2012 - 07:45 AM

Hey guys,

I'm a bit new to C# and brand new to SQL. I've been playing around with Visual Studio 2010 for a few weeks now and my few years of C++ back in my college years makes C# not too much of a pain to learn. I've run into a bit of a problem now though, my knowledge of SQL is near none. Let me try to explain what I'm trying to do first

I'm writing a program to help me at work. At my job we have many (~100) tools called PModules and each has a bunch of information tied to them. Now at first my basic understanding of programming got me thinking I could make a PModule class and make a ton of PModule objects. Something along the lines of:

public PModule(string iSN, string iLoc, int iNumChambers)
    {
        string SN = iSN;
        string loc = iLoc;
        int numChambers = iNumChambers;
    }

PModule J01 = new PModule("H0125", "Bay C, 3rd PM on the right", 4);

PModule J06 = new PModule("H0173", "Bay D, 1st PM on the left", 6);


Now I've looked into it and realized I can have an SQL database with columns that hold all this info. I've watched a dozen YouTube videos and read a bunch of tutorials but I can't figure out how to do exactly what I'm trying to do, they all seem to dump the whole database on a form. All I've basically figured out from these that helps me is how to make a database. What I want to try to do is search the database, which I'm guessing I could do with a loop For Loop. Say I want to find PModule J01...

for (int i = 1; i <= lenghtOfDB; i++)
        {
	    if (db.id(i).PModuleName == "J01")
		{
			found = true;
			break;
		}
        }


Now I'm not sure how to get the length of the database, which would be the condition as it counts through the IDs, then however you call that column that has the names and would check it till I found it. Once I found it I would like to make, say, textBox1.text = the number of chambers.

In the end I'm looking at making a drop down that has all these PMs (J01, J02, J03) then when they select one, they can hit a button that says Get Number of Chambers and a textBox will be set to have that number. Sorry for my ignorance and long winded'ness here but I'm at my wits end and I wanna make sure I cover all my bases. Thanks a ton for any information that can help me out here.

Is This A Good Question/Topic? 0
  • +

Replies To: Question on how to use SQL in C#

#2 tlhIn`toq  Icon User is offline

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

Reputation: 5535
  • View blog
  • Posts: 11,857
  • Joined: 02-June 10

Re: Question on how to use SQL in C#

Posted 27 November 2012 - 08:28 AM

Q:... how to do x,y,z with a database {probably for the first time}...
A: Read this tutorial
Entire section of tutorials
Parameterizing Your SQL Queries: The RIGHT Way To Query A Database.
Using SqlDependency to monitor SQL database changes
Was This Post Helpful? 3
  • +
  • -

Page 1 of 1