行未添加到 table

row is not getting added to table

DataSet datare=new dataset1(); //global variable  

public partial class main_inherit : sphynx
{         
    public main_inherit():base(@"Data Source=PC5;Initial Catalog=clinic_Main;User ID=sa")
    {
    }
    string constr;
    public override SqlDataReader getval(string query)
    {
        constr = base.connector();
        try
        {
            sqlcon.Open();
            sqlask = new SqlCommand(query, sqlcon);
            rdr = sqlask.ExecuteReader();


        }
        catch { }
        sqlcon.Close();
        return rdr;
    }

    public virtual void  filldata(string text)
    {
        Form2 datare=new Form2();
        DataRow dr=datare.ds.Tables["details"].NewRow();

        dr["id"] = base.valueofstr("select patientid from master_bill1 where transactid='" + text + "' ","patientid");
        dr["name"] = base.valueofstr("select name from cust_det where id='"+dr["id"]+"'", "name");
        dr["billno"] = datare.textBox1.Text;
        dr["paidate"] = base.valueofstr
            ("select paidate from master_bill1 where transactid='"+text+"'","paidate");

        datare.ds.Tables["details"].ImportRow(dr);                
    }
}

该行未添加到 table 以显示 crystal 报告 有人可以帮助我吗 我已经尝试在 gridview 中查看 table 它也显示空行.

问题是这一行:

datare.ds.Tables["details"].ImportRow(dr);

什么也没做。引用 MSDN,

"If the DataRow that is passed as a parameter is in a detached state, it is ignored, and no exception is thrown."

Detatched 意味着它还没有被添加到 DataTable 中。可能您根本不需要 ImportRow,而是在 table.

的行集合上使用 Add
datare.ds.Tables["details"].Rows.Add(dr);

基本上,ImportRow 用于复制现有行并将其附加到 table,而不是添加新行。