本文介绍了Asp.Net GridView在多个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
1.我希望在gridview1中显示..
filename,fileInfo,filepath,createdOn,statusId,statusName
1.I want display in gridview1..
filename,fileInfo,filepath,createdOn,statusId,statusName
string query ="select f.fileName,(f.fileType + '' + f.fileSize)as fileInfo,f.filepath,f.createdOn,f.statusId,s.statusName from fileInfo As f left join status As s on f.statusId=s.statusId where userId=(select userId from userInfo where email = '" + key + "')"
2.如何写入filetype和filesize合并为一列。在同一列中,它将显示如下
filetype
filesize
预付谢谢朋友!
2. how to write in filetype and filesize merge into one one column. in same column it will display like this
filetype
filesize
Advance Thanks Friends!
推荐答案
string query ="select f.fileName,(CONVERT(varchar(100), f.fileType) + ' - ' +CONVERT(varchar(100),f.fileSize))as fileInfo,f.filepath,f.createdOn,f.statusId,s.statusName from fileInfo As f left join status As s on f.statusId=s.statusId where userId=(select userId from userInfo where email = '" + key + "')"
ALTER PROC Grid_getAlldata @email NVARCHAR(50)
AS
BEGIN
SELECT fileInfo.fileName, (CONVERT(VARCHAR(40),fileInfo.fileSize) + '<br/>' +CONVERT(VARCHAR(40), fileInfo.fileType)) AS fileInformation,
fileInfo.filePath, fileInfo.createdOn,fileInfo.statusId,status.statusName FROM fileInfo INNER JOIN STATUS
ON fileInfo.statusId=status.statusId WHERE userId IN (SELECT userId FROM userInfo WHERE email=@email)
END
[/ EDIT]
--Amit
[/EDIT]
--Amit
Create PROCEDURE usp_getAlldata
(
@Key varchar(50)
)
AS
BEGIN
select f.fileName,(CONVERT(varchar(50),f.fileType) + '<br>' + CONVERT(varchar(50),f.fileSize)) as fileInfo,f.filepath,f.createdOn,f.statusId,s.statusName from fileInfo As f left join status As s on f.statusId=s.statusId where userId=(select userId from userInfo where email = @Key)
END
GO
protected void Page_Load(object sender, EventArgs e)
{
string emailkey = "put your key here";
DataSet ds = new DataSet();
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
cn.Open();
SqlCommand cmd = new SqlCommand("usp_getAlldata", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Key", emailkey);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
cmd.ExecuteNonQuery();
GridView1.DataSource = ds;
GridView1.DataBind();
}
这篇关于Asp.Net GridView在多个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!