You must Sign In to post a response.
  • Category: ASP.NET

    How to store multiple data in datatable using gridview input.

    Dear Friends
    I have an one gridview. in this gridview i entered more than 10 rows values using input control.. those values should be stored in datatable also bind with gireview.. i implemenred that input controls automatically added in gridview.. how its possible. can any one guide..

    after i stored that data into datatable i click save button for insert data into database..
  • #764714
    Hi,

    You asked the same question with different title, please review your previous question to get our comments for the same.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #764729
    Yes agree with Mr. naveensanagasetti.
    refer this URL:
    http://www.dotnetspider.com/forum/ViewForum.aspx?ForumId=344084

  • #764740
    Hi,

    Please check below code,

    foreach (GridViewRow GridItem in GridView1.Rows)
    {
    strName = GridItem.Cells[1].Text;
    strAddress = GridItem.Cells[2].Text;


    SqlConnection Con = new SqlConnection(clspublic.GetConnectionString());
    using(con)
    {
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = Con;
    cmd.CommandText = @"INSERT INTO Customer
    (Name, Address) VALUES (@Name,@Address)";

    cmd.Parameters.AddWithValue("@Name", strName.ToString());
    cmd.Parameters.AddWithValue("@Address", strAddress.ToString());
    cmd.ExecuteNonQuery();
    }


    Regards,
    Asheej T K
    Microsoft MVP[ASP.NET/IIS]
    DotNetSpider MVM

  • #764755
    You can do it in two ways.
    First Add the data into the database, then get the data from the database and assign the data souce of the grid view and do databind.
    OR
    Add the value in the grid then finally save that into the database

    For the first way.

    1. Design the Input controls for adding the data into the grid view.
    2. Have one button "Add data". In the butting click you can handle the "ADO.NET", for inser the data into the database

    SqlConnection MySqlConnection = new SqlConnection(ConnectionString);
    SqlCommand MySqlCommand = new SqlCommand();
    MySqlCommand .Connection = MySqlConnection ;
    MySqlCommand .CommandText = "Insert statement";
    MySqlCommand .ExecuteNonQuery();

    3. As soon as added the data . Retrieve the data from the database and bind it into the gridview

    You can handle it using Jquery AJAX also.

    By Nathan
    Direction is important than speed


Sign In to post your comments