如何将结果与select语句相除? [英] how to divide result from select statement ?

查看:89
本文介绍了如何将结果与select语句相除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从item1 =''"+ textbox1.text +"''
的项目中选择item1,item2
如何接收两个变量,一个用于item1,另一个用于item2

select item1,item2 from items where item1=''"+textbox1.text+"''

how can i recieve result in two variables one for item1 and another for item2

推荐答案

string item1,item2;
SqlDataAdapter适配器=新的SqlDataAdapter(mycommand);
DataTable dt = new DataTable();
adapter.Fill(dt);
item1 = dt.Rows [0] ["item1"].ToString();
item2 = dt.Rows [0] ["item2"].ToString();
string item1, item2;
SqlDataAdapter adapter = new SqlDataAdapter(mycommand);
DataTable dt=new DataTable();
adapter.Fill(dt);
item1 = dt.Rows[0]["item1"].ToString();
item2 = dt.Rows[0]["item2"].ToString();


DataTable中使用DataAdapter.Fill获取数据,并使用dt.Rows[0].Item[0]dt.Rows[0].Item[1]



使用ExecuteReader获取SqlDataReader中的数据,并使用sr.Item[0]sr.Item[1]



ExecuteScalar与item1和item2分别使用两次.
Get the data using DataAdapter.Fill in DataTable and use dt.Rows[0].Item[0] and dt.Rows[0].Item[1]

or

use ExecuteReader to get data in SqlDataReader and use sr.Item[0] and sr.Item[1]

or

use ExecuteScalar twice with item1 and item2 separately.


从item1 =''"+ textbox1.text +"''
的项目中选择item1,item2
执行此查询并将结果放入DataSet(ds)
现在
var result1 = ds.Tables [0] .Rows [0] ["item1"]

var result2 = ds.Tables [0] .Rows [0] ["item2"]

这是做事的一种方式,

另一个是

编写一个具有两个查询的存储过程,如

从item1 =''"+ textbox1.text +"''
的项目中选择item1
从item1 =''"+ textbox1.text +"''
的项目中选择item2
现在执行以上SP并将结果放入一个数据集并执行以下操作,

var Result1 = ds.Tables [0] .Rows [0] ["item1"]

var Result2 = ds.Tables [1] .Rows [0] ["item2"]

希望对您有帮助.

全部d最佳.
select item1,item2 from items where item1=''"+textbox1.text+"''

execute this query and take result into DataSet(ds)
now
var result1 = ds.Tables[0].Rows[0]["item1"]

var result2 = ds.Tables[0].Rows[0]["item2"]

This is one way you can do the things ,

Another is

Write a stored procedure having two query like

select item1 from items where item1=''"+textbox1.text+"''

select item2 from items where item1=''"+textbox1.text+"''

and now execute above SP and take result into one dataset and do following things,

var Result1= ds.Tables[0].Rows[0]["item1"]

var Result2 = ds.Tables[1].Rows[0]["item2"]

I hope this will help you.

All d Best.


这篇关于如何将结果与select语句相除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆