Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can someone help me

HERE IS THE ERROR CODE
HTML
Incorrect syntax near '.'. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '.'.

Source Error: 



Line 663:                cmd.CommandTimeout = 600;                
Line 664:                cn.Open();
Line 665:                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
Line 666:                rdr.Read();
Line 667:
  

 Source File:  c:\Inetpub\wwwroot\VihuMaatriks\Konstruktor.aspx.cs    Line:  665 

Stack Trace: 



[SqlException (0x80131904): Incorrect syntax near '.'.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +404
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +412
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1363
   System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +59
   System.Data.SqlClient.SqlDataReader.get_MetaData() +118
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6388241
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +6389810
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +538
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +28
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +256
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) +228
   Konstruktor.Button1_Click(Object sender, EventArgs e) in c:\Inetpub\wwwroot\VihuMaatriks\Konstruktor.aspx.cs:665
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707


AND HERES THE BUTTON SOURCE CODE

HTML
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Konstruktor : System.Web.UI.Page
{
    
    public String String1
    {
        get { return Label1.Text; }
    }
    public String String2
    {
        get { return Label2.Text; }
    }
    public String String3
    {
        get { return Label3.Text; }
    }
    public String String4
    {
        get { return Label4.Text; }
    }
    public String String5
    {
        get { return Label5.Text; }
    }
    public String StringZ
    {
        get { return LabelZ.Text; }
    }
    public String StringX
    {
        get { return Label6.Text; }
    }
    public String StringPalgigrupp
    {
        get { return Label_palgigrupp.Text; }
    }

     public String Username
     {    
         get {
            string username= HttpContext.Current.User.Identity.Name.ToString();
            int kaldkriips = username.IndexOf("\\") + 1;
            username = username.Substring(kaldkriips, username.Length - kaldkriips);
            username = char.ToUpper(username[0]) + username.Substring(1);
            return username;
         }
     }

    
    
    protected void Page_Load(object sender, EventArgs e)
    {
        int kuu_paev = (int)DateTime.Today.Day - 1;
        if ((MLCalendar1.SelectedDate.Year == 1) || (MLCalendar1.SelectedDate.Year == null)) MLCalendar1.SelectedDate = DateTime.Today.AddDays(-kuu_paev);
        //if ((MLCalendar2.SelectedDate.Year == 1) || (MLCalendar2.SelectedDate.Year == null)) MLCalendar2.SelectedDate = DateTime.Today;

/*        if ((MLCalendar1.SelectedDate.Year == 1) || (MLCalendar1.SelectedDate.Year == null))    //st. et on algväärtustamata
            if (kuu_paev < 3)
            {
                MLCalendar1.SelectedDate = DateTime.Today.AddMonths(-1).AddDays(-(kuu_paev));
            }
            else              MLCalendar1.SelectedDate = DateTime.Today.AddDays(-kuu_paev);
        if ((MLCalendar2.SelectedDate.Year == 1) || (MLCalendar2.SelectedDate.Year == null))
            if (kuu_paev < 3) MLCalendar2.SelectedDate = DateTime.Today.AddDays(-(kuu_paev+1));
            else              MLCalendar2.SelectedDate = DateTime.Today;

        MLCalendar1.VisibleDate = MLCalendar1.SelectedDate;
        MLCalendar2.VisibleDate = MLCalendar2.SelectedDate;  */

        if (DropDownList1.SelectedValue == "532")
        {
            Button1.PostBackUrl = "K035.aspx";
        }
        else if (DropDownList1.SelectedValue == "523")
        {
            Button1.PostBackUrl = "HK.aspx";
        }
        else if (DropDownList1.SelectedValue == "522")
        {
            Button1.PostBackUrl = "TK.aspx";
        }
        else if (DropDownList1.SelectedValue == "524")
        {
            Button1.PostBackUrl = "MD.aspx";
        }        
        else if (DropDownList1.SelectedValue == "521")
        {
            Button1.PostBackUrl = "PK.aspx";
        }
        else if (DropDownList1.SelectedValue == "525")
        {
            Button1.PostBackUrl = "TM.aspx";
        }
        else if (DropDownList1.SelectedValue == "531")
        {
            Button1.PostBackUrl = "VR.aspx";
        }
        else if (DropDownList1.SelectedValue == "535")
        {
            Button1.PostBackUrl = "TK1mm.aspx";
        }
        else if (DropDownList1.SelectedValue == "536")
        {
            Button1.PostBackUrl = "TK135mm.aspx";
        }
        else if (DropDownList1.SelectedValue == "538")
        {
            Button1.PostBackUrl = "HK.aspx";  //"HK07.aspx";
        }
        else if (DropDownList1.SelectedValue == "539")
        {
            Button1.PostBackUrl = "HK.aspx"; //"HK09.aspx";
        }
        else if (DropDownList1.SelectedValue == "540")
        {
            Button1.PostBackUrl = "TK09.aspx";
        }
        else if (DropDownList1.SelectedValue == "541")
        {
            Button1.PostBackUrl = "TK15.aspx";
        } 
        
        Label1.Visible = false;
        Label2.Visible = false;
        Label3.Visible = false;
        Label4.Visible = false;
        Label5.Visible = false;
        LabelZ.Visible = false;
        Label_palgigrupp.Visible = false;

        Label1.Text = "Mõõteliin: " + MLCalendar1.SelectedDate.ToLongDateString() + " - " +
                                        MLCalendar2.SelectedDate.ToLongDateString();
        Label2.Text = "Giljotiin: ";
        Label3.Text = "Kuivati: ";
        Label4.Text = "Spoonimasin: ";
        Label5.Text = "Toorme: ";
        LabelZ.Text = String.Empty;
        Label_palgigrupp.Text = String.Empty;

        // Showing/Hiding Calendars for Giljotiin, Kuivati, Spoonimasin, Toorme

        if (GiTimeCheckBox.Checked == true)
        {
            GiCalendar1.Visible = false;
            GiCalendar2.Visible = false;
        }
        if (GiTimeCheckBox.Checked == false)
        {
            GiCalendar1.Visible = true;
            GiCalendar2.Visible = true;
            Label2.Text = Label2.Text + " " + GiCalendar1.SelectedDate.ToLongDateString() + " - " +
                GiCalendar2.SelectedDate.ToLongDateString();
        }

        if (KuTimeCheckBox.Checked == true)
        {
            KuCalendar1.Visible = false;
            KuCalendar2.Visible = false;
        }
        if (KuTimeCheckBox.Checked == false)
        {
            KuCalendar1.Visible = true;
            KuCalendar2.Visible = true;
            Label3.Text = Label3.Text + " " + KuCalendar1.SelectedDate.ToLongDateString() + " - " +
                KuCalendar2.SelectedDate.ToLongDateString();
        }

        if (SpTimeCheckBox.Checked == true)
        {
            SpCalendar1.Visible = false;
            SpCalendar2.Visible = false;
        }
        if (SpTimeCheckBox.Checked == false)
        {
            SpCalendar1.Visible = true;
            SpCalendar2.Visible = true;
            Label4.Text = Label4.Text + " " + SpCalendar1.SelectedDate.ToLongDateString() + " - " +
                SpCalendar2.SelectedDate.ToLongDateString();
        }

        if (ToormeTimeCheckBox.Checked == true)
        {
            ToormeCalendar1.Visible = false;
            ToormeCalendar2.Visible = false;
        }

        if (ToormeTimeCheckBox.Checked == false)
        {
            ToormeCalendar1.Visible = true;
            ToormeCalendar2.Visible = true;
            Label5.Text = Label5.Text + " ostetud " + ToormeCalendar1.SelectedDate.ToLongDateString() + " - " +
                ToormeCalendar2.SelectedDate.ToLongDateString();
        }


        // Enabling/Disabling DropDowns for Giljotiin, Kuivati, Spoonimasin, Toorme

        if (MLOperCheckBox.Checked == true)
        {
            MLOperDrop.Enabled = false;
           
        }
        if (MLOperCheckBox.Checked == false)
        {
            MLOperDrop.Enabled = true;
            Label1.Text = Label1.Text + ", " + MLOperDrop.SelectedItem.ToString();
        }


        /////////////////////////////////
        if (GiOperCheckBox.Checked == true)
        {
            GiOperDrop.Enabled = false;            
        }
        if (GiOperCheckBox.Checked == false)
        {
            GiOperDrop.Enabled = true;
            Label2.Text = Label2.Text + ", " + GiOperDrop.SelectedItem.ToString();
        }


        if (GiDeviceCheckBox.Checked == true)
        {
            GiDeviceDrop.Enabled = false;
        }
        if (GiDeviceCheckBox.Checked == false)
        {
            GiDeviceDrop.Enabled = true;
            Label2.Text = Label2.Text + ", " + GiDeviceDrop.SelectedItem.ToString();
        }

        /////////////////////////////////

        if (KuOperCheckBox.Checked == true)
        {
            KuOperDrop.Enabled = false;
        }
        if (KuOperCheckBox.Checked == false)
        {
            KuOperDrop.Enabled = true;
            Label3.Text = Label3.Text + ", " + KuOperDrop.SelectedItem.ToString();
        }
        if (KuDeviceCheckBox.Checked == true)
        {
            KuDeviceDrop.Enabled = false;
        }
        if (KuDeviceCheckBox.Checked == false)
        {
            KuDeviceDrop.Enabled = true;
            Label3.Text = Label3.Text + ", " + KuDeviceDrop.SelectedItem.ToString();
        }

        /////////////////////////////////
        if (SpOperCheckBox.Checked == true)
        {
            SpOperDrop.Enabled = false;
        }
        if (SpOperCheckBox.Checked == false)
        {
            SpOperDrop.Enabled = true;
            Label4.Text = Label4.Text + ", " + SpOperDrop.SelectedItem.ToString();
        }
        if (SpDeviceCheckBox.Checked == true)
        {
            SpDeviceDrop.Enabled = false;
        }
        if (SpDeviceCheckBox.Checked == false)
        {
            SpDeviceDrop.Enabled = true;
            Label4.Text = Label4.Text + ", " + SpDeviceDrop.SelectedItem.ToString();
        }

        /////////////////////////////////
        if (HankijaCheckBox.Checked == true)
        {
            HankijaDrop.Enabled = false;
        }
        if (HankijaCheckBox.Checked == false)
        {
            HankijaDrop.Enabled = true;
            Label5.Text = Label5.Text + ", " + HankijaDrop.SelectedItem.ToString();
        }
        
        
        if (KvalCheckBox.Checked == false)
        {
            KvalDrop.Enabled = true;
            Label5.Text = Label5.Text + ", " + KvalDrop.SelectedItem.ToString();
        }
        if (KvalCheckBox.Checked == true)
        {
            KvalDrop.Enabled = false;            
        }

        if (ScanCheckBox.Checked == false)
        {
            ScanDrop.Enabled = true;
            Label5.Text = Label5.Text + " " + ScanDrop.SelectedItem.ToString();
        }
        if (ScanCheckBox.Checked == true)
        {
            ScanDrop.Enabled = false;
        }


        if (DiamCheckBox.Checked == true)
        {
            Diam1TextBox.Enabled = false;
            Diam2TextBox.Enabled = false;
        }
        if (DiamCheckBox.Checked == false)
        {
            Diam1TextBox.Enabled = true;
            Diam2TextBox.Enabled = true;
            Label5.Text = Label5.Text + ", diameeter " + Diam1TextBox.Text.ToString() + " - "
                    + Diam2TextBox.Text.ToString();

        }

        if (PartiiCheckBox.Checked == false)
        {
            PartiiTextBox.Enabled = true;
            Label5.Text = Label5.Text + ", vastuvõtu akt nr " + PartiiTextBox.Text.ToString() + " ";
        }
        if (PartiiCheckBox.Checked == true)
        {
            PartiiTextBox.Enabled = false;
        }

        if (BeamCheckBox.Checked == false)
        {
            BeamDownList.Enabled = true;
            //BeamDownList.DataBind();
        }
        else   //(BeamCheckBox.Checked == true)
        {
            BeamDownList.Enabled = false;
        }

        //ZmaterjalTextBox.Text = String.Empty;
        LabelZ.Text = String.Empty;   //"Z-materjal: " + ZmaterjalTextBox.Text.ToString();
       

        
        
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        // Getting params for Measuring Line...
        string MLDate1 = "'" + MLCalendar1.SelectedDate.Month.ToString() + '/' +
                               MLCalendar1.SelectedDate.Day.ToString() + '/' +
                               MLCalendar1.SelectedDate.Year.ToString() + "'";

        /*string MLDate2 = "'" + MLCalendar2.SelectedDate.Month.ToString() + '/' +
                               MLCalendar2.SelectedDate.Day.ToString() + '/' +
                               MLCalendar2.SelectedDate.Year.ToString() + " 23:59:59'";*/

        string MLDate2;
        if ((MLCalendar2.SelectedDate.Year == 1) || (MLCalendar2.SelectedDate.Year == null))
        {
            //char[] delimiterChars = { '\\'};
            //string[] username = HttpContext.Current.User.Identity.Name.ToString().Split(delimiterChars);
            //string username = HttpContext.Current.User.Identity.Name.ToString();
            //int kaldkriips = username.IndexOf("\\") + 1;
            //username = username.Substring(kaldkriips, username.Length - kaldkriips);
            //username = char.ToUpper(username[0]) + username.Substring(1);
            InfoLabel.Text = "Vali lõpukuupäev, " + Username;
            InfoLabel.Visible = true;
            //InfoLabel.ForeColor = "FF0000";
            return;
        }
        else
        {
            InfoLabel.Visible = false;
            MLDate2 = "'" + MLCalendar2.SelectedDate.Month.ToString() + '/' +
                              MLCalendar2.SelectedDate.Day.ToString() + '/' +
                              MLCalendar2.SelectedDate.Year.ToString() + " 23:59:59'";

        }

        int WGFurn = int.Parse(DropDownList1.SelectedValue.ToString());
        string MLOper1 = "1";
            if (MLOperCheckBox.Checked == false)
            {
                MLOper1 = MLOperDrop.SelectedValue;
            }
        string MLOper2 = "999999";
            if (MLOperCheckBox.Checked == false)
            {
                MLOper2 = MLOperDrop.SelectedValue;
            }

        // Getting params for Clipper/Giljotiin...
        string GiDate1 = "'1/1/2005'";
            if (GiTimeCheckBox.Checked == false)
            {
                GiDate1 = "'" + GiCalendar1.SelectedDate.Month.ToString() + '/' +
                                GiCalendar1.SelectedDate.Day.ToString() + '/' +
                                GiCalendar1.SelectedDate.Year.ToString() + "'";
            }
        string GiDate2 = "'" + DateTime.Now.Month.ToString() + '/' +
                               DateTime.Now.Day.ToString() + '/' +
                               DateTime.Now.Year.ToString() + " 23:59:59'";

            if (GiTimeCheckBox.Checked == false)
            {
                GiDate2 = "'" + GiCalendar2.SelectedDate.Month.ToString() + '/' +
                                GiCalendar2.SelectedDate.Day.ToString() + '/' +
                                GiCalendar2.SelectedDate.Year.ToString() + " 23:59:59'";
            }
        string GiDevice1 = "1";
            if (GiDeviceCheckBox.Checked == false)
            {
                GiDevice1 = GiDeviceDrop.SelectedValue;
            }
        string GiDevice2 = "999999";
            if (GiDeviceCheckBox.Checked == false)
            {
                GiDevice2 = GiDeviceDrop.SelectedValue;
            }
        string GiOper1 = "1";
            if (GiOperCheckBox.Checked == false)
            {
                GiOper1 = GiOperDrop.SelectedValue;
            }
        string GiOper2 = "999999";
            if (GiOperCheckBox.Checked == false)
            {
                GiOper2 = GiOperDrop.SelectedValue;
            }

        // Getting params for Dryer/Kuivati...
        string KuDate1 = "'1/1/2005'";
            if (KuTimeCheckBox.Checked == false)
            {
                KuDate1 = "'" + KuCalendar1.SelectedDate.Month.ToString() + '/' +
                                KuCalendar1.SelectedDate.Day.ToString() + '/' +
                                KuCalendar1.SelectedDate.Year.ToString() + "'";
            }
        string KuDate2 = "'" + DateTime.Now.Month.ToString() + '/' +
                                   DateTime.Now.Day.ToString() + '/' +
                                   DateTime.Now.Year.ToString() + " 23:59:59'";

            if (KuTimeCheckBox.Checked == false)
            {
                KuDate2 = "'" + KuCalendar2.SelectedDate.Month.ToString() + '/' +
                                KuCalendar2.SelectedDate.Day.ToString() + '/' +
                                KuCalendar2.SelectedDate.Year.ToString() + " 23:59:59'";
            }

        string KuDevice1 = "1";
            if (KuDeviceCheckBox.Checked == false)
            {
                KuDevice1 = KuDeviceDrop.SelectedValue;
            }
        string KuDevice2 = "999999";
            if (KuDeviceCheckBox.Checked == false)
            {
                KuDevice2 = KuDeviceDrop.SelectedValue;
            }
        string KuOper1 = "1";
            if (KuOperCheckBox.Checked == false)
            {
                KuOper1 = KuOperDrop.SelectedValue;
            }
        string KuOper2 = "999999";
            if (KuOperCheckBox.Checked == false)
            {
                KuOper2 = KuOperDrop.SelectedValue;
            }
        
        // Getting params for Veneermachine/Spoonimasin...
        
        string SpDate1 = "'1/1/2005'";
            if (SpTimeCheckBox.Checked == false)
            {
                SpDate1 = "'" + SpCalendar1.SelectedDate.Month.ToString() + '/' +
                                SpCalendar1.SelectedDate.Day.ToString() + '/' +
                                SpCalendar1.SelectedDate.Year.ToString() + "'";
            }
        string SpDate2 = "'" + DateTime.Now.Month.ToString() + '/' +
                                   DateTime.Now.Day.ToString() + '/' +
                                   DateTime.Now.Year.ToString() + " 23:59:59'";

            if (SpTimeCheckBox.Checked == false)
            {
                SpDate2 = "'" + SpCalendar2.SelectedDate.Month.ToString() + '/' +
                                SpCalendar2.SelectedDate.Day.ToString() + '/' +
                                SpCalendar2.SelectedDate.Year.ToString() + " 23:59:59'";
            }
        
        string SpDevice1 = "1";
            if (SpDeviceCheckBox.Checked == false)
            {
                SpDevice1 = SpDeviceDrop.SelectedValue;
            }
        string SpDevice2 = "999999";
            if (SpDeviceCheckBox.Checked == false)
            {
                SpDevice2 = SpDeviceDrop.SelectedValue;
            }
        string SpOper1 = "1";
            if (SpOperCheckBox.Checked == false)
            {
                SpOper1 = SpOperDrop.SelectedValue;
            }
        string SpOper2 = "999999";
            if (SpOperCheckBox.Checked == false)
            {
                SpOper2 = SpOperDrop.SelectedValue;
            } 
        // Getting params for Toorme...
        
        string ToormeDate1 = "'1/1/2005'";
            if (ToormeTimeCheckBox.Checked == false)
            {
                ToormeDate1 = "'" + ToormeCalendar1.SelectedDate.Month.ToString() + '/' +
                                ToormeCalendar1.SelectedDate.Day.ToString() + '/' +
                                ToormeCalendar1.SelectedDate.Year.ToString() + "'";
            }
        string ToormeDate2 = "'" + DateTime.Now.Month.ToString() + '/' +
                                   DateTime.Now.Day.ToString() + '/' +
                                   DateTime.Now.Year.ToString() + " 23:59:59'";

            if (ToormeTimeCheckBox.Checked == false)
            {
                ToormeDate2 = "'" + ToormeCalendar2.SelectedDate.Month.ToString() + '/' +
                                ToormeCalendar2.SelectedDate.Day.ToString() + '/' +
                                ToormeCalendar2.SelectedDate.Year.ToString() + " 23:59:59'";
            }
        
        string Hankija1 = "0";
        string Hankija2 = "999999";

            if (HankijaCheckBox.Checked == false)
            {
                Hankija1 = HankijaDrop.SelectedValue;
                Hankija2 = HankijaDrop.SelectedValue;
            } 
        
        string Kval1 = "1";
        string Kval2 = "255";   //andmebaasis tinyint; max(tinyint)=255!
            if (KvalCheckBox.Checked == false)
            {
                Kval1 = KvalDrop.SelectedValue;
                Kval2 = KvalDrop.SelectedValue;
            }

        string ScanPartiiID = ScanDrop.SelectedValue;
        string BeamGroupID = "0";
        string IntermecOff = "99999999"; //Disable Intermec ScanFilter
            if (ScanCheckBox.Checked == false || BeamCheckBox.Checked == false)
            {
                IntermecOff = "-1"; //Enable Intermec ScanFilter              
            }

            if (BeamCheckBox.Checked == false)
            {
                BeamGroupID = BeamDownList.SelectedValue;
                Label_palgigrupp.Text = "Valitud palkide grupp: " + BeamDownList.SelectedItem.Text;
            }


        string Diam1 = "1";
        string Diam2 = "999999";
        if (DiamCheckBox.Checked == false)
        {
            try
            {
                Diam1 = int.Parse(Diam1TextBox.Text).ToString();
                Diam2 = int.Parse(Diam2TextBox.Text).ToString();
            }
            catch (FormatException)
            {
                
            }
        }

        string Partii1 = "0";
        string Partii2 = "99999999";
        if (PartiiCheckBox.Checked == false)
        {
            try
            {
                Partii1 = int.Parse(PartiiTextBox.Text).ToString();
                Partii2 = int.Parse(PartiiTextBox.Text).ToString();
            }
            catch (FormatException)
            {

            }
        }

        //string Zmaterjal = null;
        string GrubeStart = "0";
        string GrubeEnd = "99999999";
        if (ZmaterjalTextBox.Text != String.Empty)
        {
            try
            {
                //Zmaterjal = int.Parse(ZmaterjalTextBox.Text).ToString();
                GrubeStart = int.Parse(ZmaterjalTextBox.Text).ToString();
                GrubeEnd = GrubeStart;
                LabelZ.Text = "Z-materjal: " + GrubeStart;
            }
            catch (FormatException)
            {
            }
        }
        else
        {
            LabelZ.Text = String.Empty;
        }        

        //Label6.Text =
        // "EXEC spCreateHeikiBeamsMD " +
        //MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
        //GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
        //KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
        //SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
        //ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
        //Kval1 + ", " + Kval2 + ", " + Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2;
        
       



        // Firing appropriate SP, according to selected species      

        ///////////////////////////////////////////////////////////////////////////////

        // TREIKASK SP //

        if (DropDownList1.SelectedValue == "522" ||
            DropDownList1.SelectedValue == "540" ||
            DropDownList1.SelectedValue == "541")
        {
      
            
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateAnneTKMatrix " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + ScanPartiiID + ", " + IntermecOff + ", " +
                Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2 + ", " + BeamGroupID + ", " + GrubeStart + ", " + GrubeEnd + ", " + Username;
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cmd.CommandTimeout = 600;                
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spUpdateAnneTKMatrix";
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateHeikiBeamsTK " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + ScanPartiiID + ", " + IntermecOff + ", " +
                Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2 + ", " + BeamGroupID + ", " + GrubeStart + ", " + GrubeEnd;
                SqlCommand cmd3 = new SqlCommand(SQLqry, cn);
                Label6.Text = SQLqry;
                cmd3.CommandTimeout = 600;
                cn.Open();
                SqlDataReader rdr = cmd3.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }
        }

        ///////////////////////////////////////////////////////////////////////////////

        ///////////////////////////////////////////////////////////////////////////////

        // TREIKASK 1 MM //

        if (DropDownList1.SelectedValue == "535")
        {


            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateAnneTK1mmMatrix " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + ScanPartiiID + ", " + IntermecOff + ", " +
                Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2 + ", " + BeamGroupID;
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cmd.CommandTimeout = 600;
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spUpdateAnneTK1mmMatrix";
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateHeikiBeamsTK " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + ScanPartiiID + ", " + IntermecOff + ", " +
                Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2 + ", " + BeamGroupID;
                SqlCommand cmd3 = new SqlCommand(SQLqry, cn);
                cmd3.CommandTimeout = 600;
                cn.Open();
                SqlDataReader rdr = cmd3.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }
        }

        ///////////////////////////////////////////////////////////////////////////////

        // TREIKASK 1,35 MM //

        if (DropDownList1.SelectedValue == "536")
        {


            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateAnneTK1_35mmMatrix " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + ScanPartiiID + ", " + IntermecOff + ", " +
                Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2 + ", " + BeamGroupID;
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cmd.CommandTimeout = 600;
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spUpdateAnneTK1_35mmMatrix";
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateHeikiBeamsTK " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + ScanPartiiID + ", " + IntermecOff + ", " +
                Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2 + ", " + BeamGroupID;
                SqlCommand cmd3 = new SqlCommand(SQLqry, cn);
                cmd3.CommandTimeout = 600;
                cn.Open();
                SqlDataReader rdr = cmd3.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }
        }



        ///////////////////////////////////////////////////////////////////////////////

        // KASK 0,35 MM //

        if (DropDownList1.SelectedValue == "532")
        {


            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateAnneTK0_35mmMatrix " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + ScanPartiiID + ", " + IntermecOff + ", " +
                Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2 + ", " + BeamGroupID;
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cmd.CommandTimeout = 600;
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spUpdateAnneTKMatrix";
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateHeikiBeamsTK035 " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + ScanPartiiID + ", " + IntermecOff + ", " +
                Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2 + ", " + BeamGroupID;
                SqlCommand cmd3 = new SqlCommand(SQLqry, cn);
                cmd3.CommandTimeout = 600;
                cn.Open();
                SqlDataReader rdr = cmd3.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }
        }




        ///////////////////////////////////////////////////////////////////////////////

        // HÖÖVELKASK SP 0,55 0,70 või 0,90 mm //

        if (DropDownList1.SelectedValue == "523" || 
            DropDownList1.SelectedValue == "538" ||
            DropDownList1.SelectedValue == "539")
        {

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateAnneHKMatrix " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + ScanPartiiID + ", " + IntermecOff + ", " +
                Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2 + ", " + BeamGroupID;
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spUpdateAnneHKMatrix";
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();
            }

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateHeikiBeamsHK " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + ScanPartiiID + ", " + IntermecOff + ", " +
                Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2 + ", " + BeamGroupID;
                SqlCommand cmd3 = new SqlCommand(SQLqry, cn);
                cmd3.CommandTimeout = 600;
                cn.Open();
                SqlDataReader rdr = cmd3.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }
        }


        

        ///////////////////////////////////////////////////////////////////////////////

        // HÖÖVELKASK SP 0,70 mm //
        
/*        if (DropDownList1.SelectedValue == "538")
        {

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateAnneHK07Matrix " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + ScanPartiiID + ", " + IntermecOff + ", " +
                Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2 + ", " + BeamGroupID;
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spUpdateAnneHKMatrix";
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();
            }

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateHeikiBeamsHK " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + ScanPartiiID + ", " + IntermecOff + ", " +
                Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2 + ", " + BeamGroupID;
                SqlCommand cmd3 = new SqlCommand(SQLqry, cn);
                cmd3.CommandTimeout = 600;
                cn.Open();
                SqlDataReader rdr = cmd3.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }
        }


        
        ///////////////////////////////////////////////////////////////////////////////

        // HÖÖVELKASK SP 0,90 mm //

        if (DropDownList1.SelectedValue == "539")
        {

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateAnneHK09Matrix " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + ScanPartiiID + ", " + IntermecOff + ", " +
                Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2 + ", " + BeamGroupID;
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spUpdateAnneHKMatrix";
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();
            }

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateHeikiBeamsHK " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + ScanPartiiID + ", " + IntermecOff + ", " +
                Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2 + ", " + BeamGroupID;
                SqlCommand cmd3 = new SqlCommand(SQLqry, cn);
                cmd3.CommandTimeout = 600;
                cn.Open();
                SqlDataReader rdr = cmd3.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }
        }

*/


        ///////////////////////////////////////////////////////////////////////////////

        // TAMM SP //

        if (DropDownList1.SelectedValue == "525")
        {

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateAnneTMMatrix " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2;
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spUpdateAnneTMMatrix";
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateHeikiBeamsTM " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2;
                SqlCommand cmd3 = new SqlCommand(SQLqry, cn);
                cmd3.CommandTimeout = 600;
                cn.Open();
                SqlDataReader rdr = cmd3.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }
        }

        ///////////////////////////////////////////////////////////////////////////////

        // MÄND SP //

        if (DropDownList1.SelectedValue == "524")
        {

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateAnneMDMatrix " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2;
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }
            
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spUpdateAnneMDMatrix";
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();
            }

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateHeikiBeamsMD " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2;
                SqlCommand cmd3 = new SqlCommand(SQLqry, cn);
                cmd3.CommandTimeout = 600;
                cn.Open();
                SqlDataReader rdr = cmd3.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////////
                
        // PÖÖK SP //

        if (DropDownList1.SelectedValue == "521")
        {

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateAnnePKMatrix " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2;
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spUpdateAnnePKMatrix";
                SqlCommand cmd = new SqlCommand(SQLqry, cn);
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();
            }

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoLaduConnectionString"].ToString()))
            {
                string SQLqry = "EXEC spCreateHeikiBeamsPK " +
                MLDate1 + ", " + MLDate2 + ", " + WGFurn + ", " + MLOper1 + ", " + MLOper2 + ", " +
                GiDate1 + ", " + GiDate2 + ", " + GiDevice1 + ", " + GiDevice2 + ", " + GiOper1 + ", " + GiOper2 + ", " +
                KuDate1 + ", " + KuDate2 + ", " + KuDevice1 + ", " + KuDevice2 + ", " + KuOper1 + ", " + KuOper2 + ", " +
                SpDate1 + ", " + SpDate2 + ", " + SpDevice1 + ", " + SpDevice2 + ", " + SpOper1 + ", " + SpOper2 + ", " +
                ToormeDate1 + ", " + ToormeDate2 + ", " + Hankija1 + ", " + Hankija2 + ", " +
                Kval1 + ", " + Kval2 + ", " + Diam1 + ", " + Diam2 + ", " + Partii1 + ", " + Partii2;
                
                SqlCommand cmd3 = new SqlCommand(SQLqry, cn);
                cmd3.CommandTimeout = 600;
                cn.Open();
                SqlDataReader rdr = cmd3.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();

            }
        }

        /////////////////////////////////////////////////////////////////////////////////////////
       
        

    }
}
Posted
Comments
Krunal Rohit 4-Mar-14 2:13am    
Just a dump code.. Use debugger and see where the exception is caught.

-KR

1 solution

Please read the guidelines for posting questions here. You have pasted your whole code whereas you just need to show us the part where the problem is.

Your SQL query is incorrect. Put a debugger and check the query that is created before executing it. Now execute the query against SQL Query Analyzer and you will know the issue. Probably some of your parameter isn't correct and causing the query to break.
 
Share this answer
 
Comments
Bernhard Hiller 4-Mar-14 4:59am    
And use parameterized queries instead of creating the query text by string concatenation - also that will help to reduce the number of such SQL errors.
Ankur\m/ 4-Mar-14 7:36am    
Absolutely!
I didn't really go through the code dump. The error was very obvious. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900