Link to home
Start Free TrialLog in
Avatar of fuzzymallets1
fuzzymallets1Flag for United States of America

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> 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);
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fuzzymallets1

ASKER

Thanks, worked very well