如何将数据集转换为int [英] How to convert dataset to int

查看:132
本文介绍了如何将数据集转换为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i使用三层架构搜索数据并绑定到gridview,我的代码是



DAL:


i am using three tier architecture for search the data and bind to gridview, My code is

DAL:

public DataSet DSet(string Stxt)
   {
       try
       {
           con = new SqlConnection(connect);
           con.Open();
           cmd = new SqlCommand("Search_sp", con);
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@searchparameter", Stxt);
           da = new SqlDataAdapter(cmd);
           ds = new DataSet();
           da.Fill(ds);
           return ds;
       }
       catch
       {
           throw;
       }
       finally
       {
           con.Close();
       }
   }



BAL:




BAL:

public int txtsrch(string txtsrch)
    {
        try
        {
            return cfdal.DSet(txtsrch);
        }
        catch
        {
            throw;
        }
        finally
        {
            cfdal = null;
        }
    }





aspx页码:





aspx page code:

protected void Button2_Click(object sender, EventArgs e)
   {
       //connection();
       //query = "Search_sp";
       //cmd = new SqlCommand(query, con);
       //cmd.CommandType = CommandType.StoredProcedure;
       //cmd.Parameters.AddWithValue("@searchparameter", txtsearch.Text).ToString();
       //search_grid.DataSource = cmd.ExecuteReader();
       //search_grid.DataBind();

       string stxt = txtsearch.Text;
       search_grid.DataSource = cfbal.txtsrch(stxt);
       search_grid.DataBind();
   }





这里我的问题是显示错误(不能将数据集转换为int)但我不知道怎么做,即使我在google中引用仍然没有得到正确的输出,

感谢您的建议....



Here my Problem is it showing Error(can't convert dataset to int) but i don't know how to do it, even though i refer in google still i didn't get proper output,
Thanks for your advice ....

推荐答案

函数 DSet 返回数据集...
The function DSet returns a dataset...
public DataSet DSet(string Stxt)

所以当你在这里使用它时

so when you use it here

public int txtsrch(string txtsrch)
    {
        try
        {
            return cfdal.DSet(txtsrch);
        }



您收到错误是因为您希望txtsrch返回 int

鉴于你以后使用


you are getting the error because you want txtsrch to return an int
Given that you later use

search_grid.DataSource = cfbal.txtsrch(stxt);

我猜你真的不想要返回 int 来自txtsrch!



尝试

I'm guessing you really don't want to return an int from txtsrch!

Try

public DataSet txtsrch(string txtsrch)

而不是


这篇关于如何将数据集转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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