I would like to thank the moderator for helping me with the code while reading row by row data using datatable and sqldata adapter.
I am worried about the speed and performance of my code since I am making round trips to the server,every time I am increment the index ind.
Please see the code below
partial class frmPersonalShared1 : System.Web.UI.Page
{
int ind;
DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
if(IsPostBack)
{
Session["ind"] = ++ind;
}
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["connString"]);
SqlCommand cmd = new SqlCommand("sp_sd", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adp = new SqlDataAdapter(cmd);
SqlParameter para = new SqlParameter("@PersonalID",SqlDbType.NVarChar);
adp.SelectCommand.Parameters.Add(para);
para.Value = Session["Personal_ID"].ToString();
SqlParameter para_out = new SqlParameter("@output", SqlDbType.Int, 4);
para_out.Direction =
ParameterDirection.Output;
adp.SelectCommand.Parameters.Add(para_out);
dt= new DataTable();
adp.Fill(dt);
showRes();
}
protected void button_click(object sender, EventArgs e)
{
Response.Write(ind);
showRes();
}
protected void showRes()
{
ind=
Convert.ToInt32(Session["ind"]);
if (dt.Rows.Count == 0)
return;
if (ind > dt.Rows.Count)
ind = 0;
TextBox1.Text = dt.Rows[ind])][0].ToString();
TextBox2.Text = dt.Rows[ind][1].ToString();
TextBox3.Text = dt.Rows[ind][2].ToString();
TextBox4.Text = dt.Rows[ind][3].ToString();
TextBox5.Text = dt.Rows[ind][4].ToString();
------
---------
TextBox6.Text = dt.Rows[ind][5].ToString();
//I have to fill more than 70 textboxes.
}
}