2017-09-01 14 views
0

関数を使ってデータベースからデータを取得していますが、それをクラスに変換してグリッドに渡すには10秒かかります。ここでグリッドにバインドするには時間がかかる

は私のコードです:ここでは

NpgsqlDataAdapter adapt = new NpgsqlDataAdapter(@"SELECT m_time_stamp, m_event_log_description, m_wind_speed, m_rpm, m_power from logs.func_event_log(
    '"+id+ @"',                
    '" + myDateFrom + @" 00:00:00' , '" + myDateTo + @" 23:59:59.999'                                   
) 
t1 (m_time_stamp timestamp without time zone, m_event_log_description text, 
m_user_description varchar, m_event_type_description varchar, 
m_wind_speed real, m_rpm real, m_power real, 
m_event_type_id int, m_event_number varchar) ", cn); 

adapt.Fill(ds); 

EventEntryForAllTurbines evnt = new EventEntryForAllTurbines(); 

は、この遅延の主な原因である:

var data = (from t in ds.AsEnumerable() select new EventEntryForAllTurbines { 
    Timestamp = (DateTime)t["m_time_stamp"], 
    Description = (string)t["m_event_log_description"], 
    WindSpeed = (float)t["m_wind_speed"], 
    RPM = (float)t["m_rpm"], 
    Power = (float)t["m_power"] 
}); 

con.Close(); 
con.Dispose(); 
return new CustomJsonResult { Data = data }; 
+0

どのようにすることができます 'のように、それは、明確な疑問を持っているので、あなたの質問を編集してくださいこれをもっと演奏してもらえますか? ' – RealCheeseLord

+1

サイドノートに。このようなSQLクエリーを作成しないでください。これは、SQLインジェクション攻撃を広く受け入れてくれます。少なくとも、パラメータ化されたクエリを使用する必要があります。 – phuzi

+0

@phuziどのように教えてくれますか、私に例やリンクを教えてもらえますか? – mrslt

答えて

1
string sql = "SELECT * FROM tbl_student WHERE studentname = @param"; 
NpgsqlCommand command = new NpgsqlCommand(sql,conn); 
command.Parameters.Add("@param", textBox_studentname.Text); //add the parameter into the sql command 

DataTable dt = new DataTable(); 
//load the DataReader object of the command to the DataTable 
dt.Load(NpgsqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection)); 
GridView1.DataSource = dt; 
関連する問題