|  | 
	                
  
    |  |  
    | 
        
        Populating a javascript Array from Server Side (2)     |  
    |  |  
 
              
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ลอง Debug ดูครับ Error line ที่เท่าไหร่ครับ  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2011-12-22 11:32:01 | By :
                            webmaster |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | อันนี้ ไม่ error ครับ แต่ว่า ไม่รู้ว่าจะแปลง ยังไง ให้มัน connect กับ sql server ได้ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2011-12-22 11:43:15 | By :
                            Aod47 |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | แป๊บครับ ไม่ยาก 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2011-12-22 11:46:43 | By :
                            webmaster |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Code (C#) 
 	System.Data.SqlClient.SqlConnection objConn = new System.Data.SqlClient.SqlConnection();
	System.Data.SqlClient.SqlCommand objCmd = new System.Data.SqlClient.SqlCommand();
	System.Data.SqlClient.SqlDataAdapter dtAdapter = new System.Data.SqlClient.SqlDataAdapter();
	DataSet ds = new DataSet();
	String strConnString,strSQL;
	strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;";
	strSQL = "SELECT * FROM customer";
	objConn.ConnectionString = strConnString;
	objCmd.Connection = objConn;
	objCmd.CommandText = strSQL;
	objCmd.CommandType = CommandType.Text;
	dtAdapter.SelectCommand = objCmd;
	dtAdapter.Fill(ds);
 
 บทความการสร้าง DataSet กับ SQL Server (System.Data.SqlClient)
 Go to : (C#) ASP.NET System.Data.SqlClient - DataSet()
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2011-12-22 11:49:15 | By :
                            webmaster |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | นำไปใส่ 
 Code (C#)
 
 using System;
using System.Data;
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 ClientSideCalcGridview : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
   {
       Session.Clear();
       DataSet ds = new DataSet();
       if (Session["dt"] == null)
       {
           ds = c();
       }
       else
       {
           ds = Session["dt"] as DataSet;
       }
       foreach (DataRow dr in ds.Tables[0].Rows)
       {
           this.ClientScript.RegisterArrayDeclaration("myArray", "'" + dr["Address"].ToString() + "'");
       }
   }
   public DataSet c()
   {
	System.Data.SqlClient.SqlConnection objConn = new System.Data.SqlClient.SqlConnection();
	System.Data.SqlClient.SqlCommand objCmd = new System.Data.SqlClient.SqlCommand();
	System.Data.SqlClient.SqlDataAdapter dtAdapter = new System.Data.SqlClient.SqlDataAdapter();
	DataSet ds = new DataSet();
	String strConnString,strSQL;
	strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;";
	strSQL = "SELECT * FROM customer";
	objConn.ConnectionString = strConnString;
	objCmd.Connection = objConn;
	objCmd.CommandText = strSQL;
	objCmd.CommandType = CommandType.Text;
	dtAdapter.SelectCommand = objCmd;
	dtAdapter.Fill(ds);
       return ds;
   }
}
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2011-12-22 11:49:32 | By :
                            webmaster |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | เร็วมากครับ 
 ขอบคุณครับ เดี๋ยวถ้ามีอะไรเพิ่มเติม จะมา post ถามอีกครับ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2011-12-22 11:54:31 | By :
                            Aod47 |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ติดปัยหาลอง Search ก้ได้ครับ จะได้ไม่ต้องรอครับ  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2011-12-22 11:57:34 | By :
                            webmaster |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |