  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                ผมมีปัญหาครับ ช่อง 4เหลี่ยมที่ผมวงไว้คือผมดึงข้อมูลมาจากหน้าอื่น พอดึงข้อมูลมาแล้วกรอกข้อมูลครบทุกช่องผลออกมาคือบันทึกเข้า Database แต่ขึ้น Error ดังภาพที่ 2 แต่พอปิดการดึงข้อมูลแล้วกรอกใส่ TextBox เอาก็ไม่เกิด Error มันเป็นอะไรหรอครับ ทำไมมันฟ้องว่าข้อมูลผมอยู่นอกดัชนี ผู้รู้ช่วยตอบทีครับ 
 
 
  
 
 
  
 
 
Code (C#) 
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Test
{
    public partial class TestEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
            DateTime daValues = DateTime.Now;
            string MyDt = daValues.ToString("yyyy-MM-dd HH:mm:ss");
            TextBox7.Text = DateTime.Now.ToString(MyDt);
            TextBox1.Text = Request.QueryString[0].ToString();
            TextBox2.Text = Request.QueryString[1].ToString();
        }
        #region Button1_Click
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text == null)
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Myscript", "alert('บันทึกการแจ้งปัญหาไม่สำเร็จกรุณาใส่ ข้อมูล')", true);
            }
            if (DropDownList4.Text == "0")
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Myscript", "alert('บันทึกการแจ้งปัญหาไม่สำเร็จกรุณาใส่ ข้อมูล')", true);
            }
            
            if (DropDownList1.Text == "กำลังดำเนินการ")
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Myscript", "alert('บันทึกการแจ้งปัญหาไม่สำเร็จกรุณาใส่ ข้อมูล')", true);
            }
            if (Request.Form["Message"] == "")
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Myscript", "alert('บันทึกการแจ้งปัญหาไม่สำเร็จกรุณาใส่ รายละเอียดการแก้ไขปัญหา')", true);
            }
            
            else
            {
                SqlConnection conn = new SqlConnection("Data Source=ARTEMIS\\SQL;Initial Catalog=SvlIT;User ID=it;Password=1234");
                conn.Open();
                SqlCommand sqlcom = conn.CreateCommand();
                SqlCommand sqlcom2 = conn.CreateCommand();
                sqlcom.CommandText = "INSERT INTO [dbo].[ItCase] ([CaseKey], [Solve], [StaffName], [CloseDT],[ExpectedDT], [CaseCode]) VALUES ('" + TextBox1.Text + "','" + Request.Form["Message"] + "', '" + DropDownList1.Text + "', '" + TextBox7.Text + "','"+TextBox8.Text+"','"+TextBox2.Text+"')";
                sqlcom2.CommandText = "Update [Case] set CaseStatusKey = '" + DropDownList4.Text + "' where CaseKey =  '" + TextBox1.Text + "'";
                //sqlcom.CommandText = "INSERT INTO[dbo].[CaseType] ( [CodeType], [NameType]) VALUES" + "('" + this.TextBox2.Text + "','" + TextBox3.Text + "')";
                sqlcom.CommandType = CommandType.Text;
                sqlcom2.CommandType = CommandType.Text;
                sqlcom2.ExecuteNonQuery();
                sqlcom.ExecuteNonQuery();
                conn.Close();
                
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Myscript", "alert('บันทึกการแจ้งปัญหาสำเร็จ')", true);
               Response.Redirect("~/TestEdit.aspx");
            }
            
        }
        #endregion
      
        protected void Button2_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text != "")
            {
                SqlConnection conn = new SqlConnection("Data Source=ARTEMIS\\SQL;Initial Catalog=SvlIT;User ID=it;Password=1234");
                conn.Open();
                SqlCommand sqlcom = conn.CreateCommand();
                sqlcom.CommandText = "Update [dbo].[ItCase] set Solve = '" + Request.Form["Message"] + "', StaffName =  '" + DropDownList1.Text + "', CloseDT = '" + TextBox7.Text + "', ExpectedDT =  '" + TextBox8.Text + "' WHERE CaseKey='" + TextBox1.Text + "'";
                sqlcom.CommandType = CommandType.Text;
                sqlcom.ExecuteNonQuery();
                conn.Close();
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Myscript", "alert('บันทึกการแจ้งปัญหาสำเร็จ')", true);
                Response.Redirect("~/TestEdit.aspx");
            }
        }
    }
}
 
 
  Tag : Web (ASP.NET), C#               
                        | 
           
          
            
		
  ประวัติการแก้ไข 2018-11-02 13:12:40 2018-11-02 13:25:40	
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2018-11-02 13:12:09 | 
                      By :
                          wiraphon | 
                      View :
                          1067 | 
                      Reply :
                          2 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  |