有关C#的简单问题,SQL提取了Int格式 [英] Simple question about C#, SQL taking a Int format out
问题描述
SqlCommand cmd = 新 SqlCommand(" 选择* FROM [t_memsch],其中[m_memcode] ='" + m_memcode_input.Text + ,conn);
SqlDataAdapter sda1 = 新 SqlDataAdapter(cmd);
DataTable ds1 = 新 DataTable();
sda1.Fill(ds1);
DateTime date1 = Convert.ToDateTime(ds1.Rows [temp] [" ].ToString() );
int 会话= ds1.Rows [temp] [" ].toInt16();
知道为什么我不能删除"m_schsession"吗?发生错误.
现在,它确实允许我使用toInt16().
int session = Int32 .Parse(ds1.Rows [temp] [" ].toString());
确保在m_schsession列中没有来自数据库的空值,并且我假设temp是代表行号的整数值. SQL语句.使用 SqlParameter [,会发生什么情况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.解决方案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.
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" tom_memcode_input.Text
这篇关于有关C#的简单问题,SQL提取了Int格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!