• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

Easy C# sql problem

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
fuzzymallets1
Asked:
fuzzymallets1
  • 2
2 Solutions
 
käµfm³d 👽Commented:
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
 
abelCommented:
> 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
 
käµfm³d 👽Commented:
Use

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

instead.
0
 
fuzzymallets1Author Commented:
Thanks, worked very well
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now