小编Esh*_*sha的帖子

Gridview 被调用两次

我有一个父网格,它调用两个子网格。但出于某种未知的原因,他们被解雇了两次。我似乎无法真正弄清楚这段代码的问题。任何人都可以指导我吗?

后端代码(C#):

protected void grdGrpPrntRpt_RowDataBound(object sender,
                                      GridViewRowEventArgs e)
{
    try
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            TextBox litGrp = (TextBox)e.Row.FindControl("litGrp");
            litGrp.Text =
              DataBinder.Eval(e.Row.DataItem, "GroupName").ToString();
            ViewState["GroupName"] = litGrp.Text;
            DataSet ds = (DataSet)ViewState["ds"];
            DataView dv = ds.Tables[3].DefaultView;
            dv.RowFilter = "GroupName='" + litGrp.Text + "'";
            DataTable dt = dv.ToTable();
            GridView gvinner = (GridView)e.Row.FindControl("grdInnerMain");
            gvinner.DataSource = dt;
            gvinner.DataBind();
        }
    }
    catch (Exception Ex)
    {
        //report error
    }
}


protected void grdInnerMain_RowDataBound(object sender,
                                      GridViewRowEventArgs e)
{
    try
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            TextBox litUsr …
Run Code Online (Sandbox Code Playgroud)

c# asp.net gridview

5
推荐指数
1
解决办法
2696
查看次数

返回给出错误的数据集值

我已经定义了以下函数,它将从表中返回3列.

public DataSet GetFunc()
    {
        int iRet = 0;
        DataSet ds = new DataSet();
        SqlConnection sqlConnection = new SqlConnection();
        try
        {
            iRet = connect(ref sqlConnection);
            if (DB_SUCCESS_CONNECT == iRet)
            {
                SqlCommand sqlCommand = new SqlCommand("", sqlConnection);                   
                String strQuery = "Select ID, Did, FirstName from Users";
                sqlCommand.CommandText = strQuery;

                SqlDataAdapter adaptor = new SqlDataAdapter(sqlCommand);
                adaptor.Fill(ds);
                sqlConnection.Close();
                return ds;                    
            }

        }
        catch (Exception e)
        {
            disconnect(ref sqlConnection);
        }
    }
Run Code Online (Sandbox Code Playgroud)

但是当我尝试构建它时,我收到错误:

错误172'GetFunc()':并非所有代码路径都返回一个值

我很困惑我哪里出错了.有人可以指导我吗?

c# asp.net dataset sqldataadapter

3
推荐指数
1
解决办法
1366
查看次数

textBox中的值未插入数据库

这是我从文本字段插入数据库的代码.

SqlConnection Connection = new SqlConnection("Data Source=ESHA\\SQLEXPRESS;Initial Catalog=Gen_Lic;User ID=sa;Password=sa@");           

SqlCommand Command = Connection.CreateCommand();

try
{
// Open Connection             
Connection.Open();
////Console.WriteLine("Connection Opened");
// Create INSERT statement with named parameters             
Command.CommandText = "INSERT  INTO Gen_Lic(Lic_No, UserID, Org, UserName, SolType, Version, Lic_Type, Meap_Supp, Lic_From, Lic_To, Supp_From, Supp_To, Max_User, Max_Mach, Mach_IP, Mach_MAC) VALUES (@Lic_No, @UserID, @Org, @UserName, @SolType, @Version, @Lic_Type, @Meap_Supp, @Lic_From, @Lic_To, @Supp_From, @Supp_To, @Max_User, @Max_Mach, @Mach_IP, @Mach_MAC)";
// Add Parameters to Command Parameters collection  

Command.Parameters.AddWithValue("@Lic_No", txtLNo.Text);
Command.Parameters.AddWithValue("@UserID", txtUID.Text);
Command.Parameters.AddWithValue("@Org", txtOrg.Text);
Command.Parameters.AddWithValue("@UserName", txtUName.Text); …
Run Code Online (Sandbox Code Playgroud)

c# database asp.net textbox

1
推荐指数
1
解决办法
1030
查看次数

从数据库中读取数据并将其显示在txt文件中

我有一个SQL Server 2005中的表,其中包含以下列:

Fname (char (50)),
MailFrom (char (50)),
MailTo (char (50)),
Subject (char (50)),
MBody (char (100)),
MailID (int)
Run Code Online (Sandbox Code Playgroud)

在表中输入行之后,我想将它们提取并存储在具有每列文本字段的文本文件/文档文件/窗口表单中.

任何建议,以获得从数据库中提取数据并将其保存在文件中的最佳方法.

c# asp.net sql-server-2005

0
推荐指数
1
解决办法
4299
查看次数