0

I have to navigate between the records from the dept table.
But when I am tryng to do that I get stuck at teh second record. and teh inc value gets reset to 0. Please let me know an alternative to this. I guess maintaining session state is an option .. but I am not sure of how to do it. Please suggest .

OracleConnection cn = null;
int Rec_Max = 0;
int inc;

DataSet ds = null;
public void Page_Load(object sender, EventArgs e)
{

    string cs = "user id=scott;password=tiger";
    cn = new OracleConnection(cs);
    cn.Open();
    // MessageBox.Show("Oracle connection opened sucessfully");
    OracleDataAdapter da = null;
    OracleCommandBuilder cmb = null;
    da = new OracleDataAdapter("select * from dept", cn);
    cmb = new OracleCommandBuilder(da);
    ds = new DataSet();
    da.Fill(ds, "deptx");
    Rec_Max = ds.Tables["deptx"].Rows.Count;
    NavigateRecords(inc);
    cn.Close();
    cn.Dispose();
}

public void NavigateRecords(int disp_rec)
{
    DataRow dr1 = ds.Tables["deptx"].Rows[inc];
     txt_DeptName.Text = dr1.ItemArray.GetValue(0).ToString();
     txt_DeptNo.Text = dr1.ItemArray.GetValue(1).ToString();
     txt_Location.Text = dr1.ItemArray.GetValue(2).ToString();
}

public void btn_Next_Click(object sender, EventArgs e)
    { 
        {
            inc++;
            NavigateRecords(inc);
            int record_number =inc;
            break;
        }

   }
}

Edited by Dani: Formatting fixed

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by Ramy Mahrous
0

If you debugged your code you'll know the error. But first thing you should modify this

string cs = "user id=scott;password=tiger";
cn = new OracleConnection(cs);
cn.Open();
// MessageBox.Show("Oracle connection opened sucessfully");
OracleDataAdapter da = null;
OracleCommandBuilder cmb = null;
da = new OracleDataAdapter("select * from dept", cn);
cmb = new OracleCommandBuilder(da);
ds = new DataSet();
da.Fill(ds, "deptx");
Rec_Max = ds.Tables["deptx"].Rows.Count;
NavigateRecords(inc);
cn.Close();
cn.Dispose();

to

if(!Page.IsPostBack)
{
string cs = "user id=scott;password=tiger";
cn = new OracleConnection(cs);
cn.Open();
// MessageBox.Show("Oracle connection opened sucessfully");
OracleDataAdapter da = null;
OracleCommandBuilder cmb = null;
da = new OracleDataAdapter("select * from dept", cn);
cmb = new OracleCommandBuilder(da);
ds = new DataSet();
da.Fill(ds, "deptx");
Rec_Max = ds.Tables["deptx"].Rows.Count;
NavigateRecords(inc);
cn.Close();
cn.Dispose();
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.