Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
SqlCommand cmd = new SqlCommand("SELECT * FROM [t_memsch] where [m_memcode]='" + m_memcode_input.Text + "'", conn);
                SqlDataAdapter sda1 = new SqlDataAdapter(cmd);
                DataTable ds1 = new DataTable();

                sda1.Fill(ds1);     

DateTime date1 = Convert.ToDateTime(ds1.Rows[temp]["m_schdate"].ToString());
                        int session = ds1.Rows[temp]["m_schsession"].toInt16();


Any idea why i cant take the "m_schsession" out? A error is occurred.

It does now allow me to use toInt16(). Only toString() is allowed.
Posted
Updated 3-Jan-12 18:20pm
v2

C#
int session =Int32.Parse(ds1.Rows[temp]["m_schsession"].toString());




Make sure you don't have null values coming from database in m_schsession column and I assume that temp is an integer value representing row number.
 
Share this answer
 
Comments
tomy_hkcg 4-Jan-12 0:21am    
perfectly worked. thanks you
Also note that you should never use literals in your SQL statements. Use SqlParameter[^] instead. That would help you with conversion related problem, protect against SQL injections etc.

For example consider what's happening if you enter "Some'data" to m_memcode_input.Text
 
Share this answer
 
Comments
tomy_hkcg 4-Jan-12 1:33am    
Note dropped. thanks for reminding.
Wendelius 4-Jan-12 1:38am    
You're welcome :)

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