我现在想执行这样一个SQL语句:select em_dept_id from employee where em_name = '"+loginname+"'",loginname为session取到的登陆用户名,这个语句查询的是一个唯一的值,em_dept_id为int型数据,请问,我怎么能把查询到的这个值附值给一个int型的变量那?
解决方案 »
- 求助,DATASET得到的数据根据某个条件排序并显示序号和根据列标题升序降序排列数据?
- 谁能给一个小点的ASP.net项目源码来练练手。
- GridView 取值问题
- 没有找到适合的方法来重写问题,改写自Scott Mitchell的代码
- [求助]邮件发送问题
- [馨郁星愿]web打印小问题,不知有人知道怎么解决否?
- 怎么把其中的一个数据集中的一个表给另外一个数据集呢
- 我用Visual Studio.net开发asp.net为什么没有属性提示
- 如何在运行时动态绑定DataGrid中的模版例中的TextBox???
- 一个小问题,各位大侠们给些指示。。。
- 系统中装了IE9和Firefox SuperPreview 中却只有IE6
- 企业网站
int i = 0;
using (SqlConnection conn = new SqlConnection("server=.;user id=sa;pwd=111;database=dbname"))
{
conn.Open();
SqlCommand cmd = new SqlCommand("select em_dept_id from employee where em_name = '" + loginname + "'", conn);
i = Convert.ToInt32(cmd.ExecuteScalar());
}
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=media2";
string qury = "declare @firm_name varchar(50)"+
"select @firm_name = playListName from playMediaList where playListId = 'P'"
+" INSERT INTO TABLE2 values(@firm_name,'xyt125')";
SqlCommand myCommand = new SqlCommand(qury, myConnection);
myConnection.Open();
try
{
myCommand.ExecuteNonQuery();
}
catch (SqlException ex)
{
MessageBox.Show("插入错误!" + ex.Message.ToString());
}
myCommand.Clone();
myConnection.Close(); 用到了申明变量@firm_name 来存储查询的结果
或者是
datareader都可以的啊