2013-02-04 21 views
-6
if (dpsessional.SelectedItem.Text.ToString().Equals("1")) 
{ 

if (lengthofbatch == 1) 
       { 

       com = new SqlCommand("insert into Attendence_Stu_Main(st_id,st_rollno,st_name,branch_name,sem_no,batch_year,batch_name,scode,sess_no,attendence,total) values (@Stid,@Strollno,@Stname,@Stbranch,@Ssemno,@Syear,@Sbatch,@Scode,@Ssessno,@Satt,@Stotal)", con); 
       } 
       else 
       { 
        if (lbsubjecttype.Text.Equals("L")) 

        { 
         com = new SqlCommand("insert into Attendence_Stu_Main(st_id,st_rollno,st_name,branch_name,sem_no,batch_year,batch_name,scode,sess_no,attendence,total) values (@Stid,@Strollno,@Stname,@Stbranch,@Ssemno,@Syear,firstchar,@Scode,@Ssessno,00,00)", con); 


         com = new SqlCommand("insert into 

Attendence_Stu_MainL1(st_id,st_rollno,st_name作爲,branch_name,sem_no,batch_year,batch_name,SCOD E,sess_no,考勤,總)值HOW火災中sqlserver的兩個插入命令與Asp.net C#

(@ STID,@ Strollno,@ Stname,@ Stbranch,@ Ssemno,@ SYEAR,@ Sbatch,@ SCODE,@ Ssessno,@的Satt,@ STOTAL)」,

CON); } 別的

    { 

COM =新的SqlCommand(「插入

Attendence_Stu_MainL1(st_id,st_rollno,st_name作爲,branch_name,sem_no,batch_year,batch_name,SCOD

E,sess_no,考勤,總)值

(@ Stid,@ Strollno,@ Stname,@ Stbranch,@ Ssemno,@ Syear,@ Sbatch,@ Scode,@ Ssessno,@ Satt,@ Stotal)「,

con);

    } 

       } 
      } 

       com.Parameters.AddWithValue("@Stid", g1.Cells[0].Text); 

com.Parameters.AddWithValue( 「@ Strollno」,g1.Cells [1]。文本); com.Parameters.AddWithValue(「@ Stname」,g1.Cells [2] .Text);

com.Parameters.AddWithValue(「@ Stbranch」,g1.Cells [3] .Text);

  com.Parameters.AddWithValue("@Ssemno", g1.Cells[4].Text); 

      com.Parameters.AddWithValue("@Syear", g1.Cells[5].Text); 

      com.Parameters.AddWithValue("@Sbatch", label1); 

      com.Parameters.AddWithValue("@Scode", label2); 

      com.Parameters.AddWithValue("@Ssessno", label3); 

      com.Parameters.AddWithValue("@Satt", textbox); 

      com.Parameters.AddWithValue("@Stotal", textbox1); 





      com.ExecuteNonQuery(); 


      con.Close(); 
     } 

     catch (SqlException ex) 
     { 

      Label5.Text = ex.Message; 

      Label5.Visible = true; 
     } 




    } 

} 

............................................ ................................................

COM =新的SqlCommand(「插入 Attendence_Stu_Main(st_id,st_rollno,st_name作爲,branch_name,sem_no,batch_year,batch_name,SCODE, sess_no,考勤,總)值 (@ STID,@ Strollno,@ Stname,@ Stbranch ,@ Ssemno,@ Syear,firstchar,@ Scode,@ Ssessno,00,00)「,con);

COM =新的SqlCommand(「插入

Attendence_Stu_MainL1(st_id,st_rollno,st_name作爲,branch_name,sem_no,batch_year,batch_name,SCOD

E,sess_no,考勤,總)值

(@ Stid,@ Strollno,@ Stname,@ Stbranch,@ Ssemno,@ Syear,@ Sbatch,@ Scode,@ Ssessno,@ Satt,@ Stotal)「,

con);

從插入命令的2

只有一個被激發和其他不fired..I已經使用

調試,它顯示的清晰穿越,但不能在表來存儲

+3

請編輯您的信息,以便它是可讀的。 – PhoenixReborn

+0

試圖從上面的混亂中理解。我已經放棄了,請在發佈之前嘗試將代碼重新格式化爲可讀。 – Steve

+0

@Steve - 我也是,放棄了。這樣一個爛攤子... – Brian

回答

4

即使這是試圖這是人類中最難以解讀的問題,我會試着回答這個問題。如果你能讓你的問題簡潔明瞭,並讓我們知道你的期望,那就去做吧。

你會不斷覆蓋你的命令。

com = new SqlCommand("insert into Attendence_Stu_Main(st_id,st_rollno,st_name,branch_name,sem_no,batch_year,batch_name,scode,sess_no,attendence,total) values (@Stid,@Strollno,@Stname,@Stbranch,@Ssemno,@Syear,firstchar,@Scode,@Ssessno,00,00)", con); 

,然後,而無需實際提交此更改的數據庫,要覆蓋它:

com = new SqlCommand("insert into Attendence_Stu_MainL1(st_id,st_rollno,st_name,branch_name,sem_no,batch_year,batch_name,scode,sess_no,attendence,total) values (@Stid,@Strollno,@Stname,@Stbranch,@Ssemno,@Syear,@Sbatch,@Scode,@Ssessno,@Satt,@Stotal)", 

我會讓他們兩種不同的SqlCommand實例。

就像一個附註,數據庫表&列命名方案,你已經進行,不是很漂亮。

+2

+1使用夜視來閱讀代碼:) – AbZy

+0

我不知道你是否正確。 +1只是因爲你試圖瞭解 – Steve

+0

@Steve:是的,我知道了......但是對於我的數據庫,我正在Attendence系統上工作,而我的大學裏有3個階段,所以我製作了3個差異。具有相同屬性的表格最終生成Excel報表,因此JOINS非常容易...感謝您的幫助,以及您的建議.. –