?
Solved

Easy C# sql problem

Posted on 2009-04-22
4
Medium Priority
?
208 Views
Last Modified: 2012-05-06
I have never really worked much with C# and I'm having a problem converting over one of my VB.Net programs. One of the problems I'm having is in my SQL connection. I am trying to copy the row info to variables. Call me dumb but I can't figure it out.

private void EpicsConnection(string SoNum, string SoItem) 
{
            try
            {
                string connectionString = "Network Library=DBMSSOCN; Data Source=vwtersvsql2v\\instance2;Initial Catalog=Epics;User ID=reports;Password=*****";
                using (SqlConnection SqlConn = new SqlConnection(connectionString))
                {
                    string queryString = string.Format("SELECT DISTINCT foy.SOItem.ReqDt, foy.Die.DieNum, foy.SOItem.OrdLen, foy.ProductionDetail.Pc, foy.Finish.Type, foy.Die.UserAlpha1, foy.Finish.FinCode, foy.SOItem.OrdQty, foy.ProductionDetail.DeptNum FROM  foy.SOItem INNER JOIN foy.SOItemDept ON foy.SOItem.SONum = foy.SOItemDept.SONum AND foy.SOItem.SOItemNum = foy.SOItemDept.SOItemNum INNER JOIN foy.Die ON foy.SOItem.DieNum = foy.Die.DieNum INNER JOIN foy.Finish ON foy.SOItem.FinCode = foy.Finish.FinCode INNER JOIN foy.ProductionDetail ON foy.SOItem.SONum = foy.ProductionDetail.SONum AND foy.SOItem.SOItemNum = foy.ProductionDetail.SOItemNum WHERE foy.SOItem.SONum = '" + SoNum + "' AND foy.SOItem.SOItemNum = '" + SoItem + "' AND foy.ProductionDetail.DeptNum = 'AGE'");
                    SqlCommand cmd = new SqlCommand(queryString, SqlConn);
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataSet ds = new DataSet();
                    SqlConn.Open();
                    da.Fill(ds, "AgeOven");
                    {      if (ds.Tables[0].Rows.Count > 0)
                        {
                            foreach(DataRow row 0 in ds.Tables[0].Rows)
                            tempDate = Convert.ToString(row["ReqDt"]);
                            tempDieNum = Convert.ToString(row["DieNum"]);
                            tempLen = Convert.ToString(row("OrdLen"));
                            tempPC = Convert.ToString(row("Pc"));
                            tempType = Convert.ToString(row("Type"));
                            tempAlpha = Convert.ToString(row("UserAlpha1"));
                            tempFin = Convert.ToString(row("FinCode"));
                            tempOrd = Convert.ToString(row("OrdQty"));
                        }
                    }
                    SqlConn.Close();
                }
            }
            catch (Exception ex)
            {
                My.Computer.Audio.PlaySystemSound(SystemSounds.Hand);
            }
            if (LstSoItem.Items.Count == 0)
            {
            }
            else
            {
                try
                {
                    LstSoItem.Items.RemoveAt(0);
                }
                catch (Exception ex)
                {
                }
            }
        }

Open in new window

0
Comment
Question by:fuzzymallets1
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 24207737
The following should be bracketed and your foreach declaration has an extra '0' in it::
foreach(DataRow row in ds.Tables[0].Rows)
{
    tempDate = Convert.ToString(row["ReqDt"]);
    tempDieNum = Convert.ToString(row["DieNum"]);
    tempLen = Convert.ToString(row("OrdLen"));
    tempPC = Convert.ToString(row("Pc"));
    tempType = Convert.ToString(row("Type"));
    tempAlpha = Convert.ToString(row("UserAlpha1"));
    tempFin = Convert.ToString(row("FinCode"));
    tempOrd = Convert.ToString(row("OrdQty"));
}
 
 
Also:
 
My does not exist in C#, so
    My.Computer.Audio.PlaySystemSound(SystemSounds.Hand);
 
will not work.

Open in new window

0
 
LVL 39

Expert Comment

by:abel
ID: 24207779
> My.Computer.Audio.PlaySystemSound(SystemSounds.Hand);
> will not work.

I agree with kaufmed: that will not work. Use "this" instead:

this.Computer.Audio.PlaySystemSound(SystemSounds.Hand);
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 2000 total points
ID: 24207811
Use

    System.Media.SystemSounds.Hand.Play();

instead.
0
 
LVL 5

Author Closing Comment

by:fuzzymallets1
ID: 31573429
Thanks, worked very well
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question