Click here to Skip to main content
14,930,722 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Button_Click(object sender, EventArgs e)
{
    string a = Request.Params.ToString();
    string[] b = Request.Params["days"].Split(',');
    string[] c = Request.Params["subject"].Split(',');
    string[] d = Request.Params["teacher"].Split(',');
    string[] f = Request.Params["StartTime"].Split(',');
    string[] g = Request.Params["EndTime"].Split(',');

    string output = "<html><body>College: Anuradha College<br />Course: " + drpCourses.SelectedItem.Text +
     "<br />Stream: " + drpBranch.SelectedItem.Text + "<br /> Section: " + drpSection.SelectedItem.Text +
     "<br/>Day\t    Subject\t     Teacher\t      Start Time\t      End Time<br />DYNAMIC</body></html>";;
    String dynamic = "";
    for (int i = 0; i < b.Length; i++)
    {
        dynamic = dynamic + " " + b[i] + "  \t" + c[i] + " \t" + d[i] + " \t" + f[i] + " \t" + g[i] + "<br />";
    }

    int h = b.Length;
    for (int i = 0; i< h; i++)
    {
        string s = "insert into V2_TimeTable(CollageId,CourseId,StreamId,SectionId,Day,SubjectId,TeacherId,StartTime,EndTime) Values("+ 1 +", "+ drpCourses.SelectedValue + "," + drpBranch.SelectedValue + "," + drpSection.SelectedValue + "," + b[i].ToString() + "," + c[i].ToString() + "," + d[i].ToString() + " , '" + f[i].ToString() + "' , '" + g[i].ToString()  + "' )";
        obj.update(s);
        Response.Write("<script LANGUAGE='JavaScript' >alert('SUCCESSFULLY INSERTED')</script>");
}


I am trying to add multiple row dynamically and trying to store all the row data in the database.I have used this Code in button click.But it is showing an error and the error is"object instance is null(not the same but its like dis) on the first line that is string a line....Can anyone help me in solving dis?
Posted
Updated 16-Nov-13 1:33am
v2

1 solution

If it is happening on this line
string a = Request.Params.ToString();
then either Request has not been initialised or does not contain Params

So your problem is not in this code, but elsewhere in your form, before you get to the point where you click the button.

Also Params returns a collection so Request.Params.ToString(); will just return descriptive text, not any value.

Further reference with an example...at msdn[^]
   
Comments
sumit sam 18-Nov-13 6:41am
   
Thanx Bro

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900