0

Hello Friend's,
step 1: I trying textbox data 1st insert in grid. it's clear
but
step 2 : Grid data not insert in data base. it's code here

  protected void btnsavedata_Click(object sender, EventArgs e)
    {


        foreach (GridViewRow g1 in gvloan.Rows)
        {
            SqlConnection con = new SqlConnection(conString);
            SqlCommand com = new SqlCommand("insert into dbo.Test_db(Pf,loan) values ('" + g1.Cells[0].Text + "','" + g1.Cells[1].Text + "')", con);
            con.Open();
            com.ExecuteNonQuery();
            con.Close();

        }

    }

Edited by Rake$h

2
Contributors
2
Replies
16
Views
3 Years
Discussion Span
Last Post by Rake$h
0

Does your code generate some type of error?

Also, its a better idea to use Parameters... for example...

SqlConnection con = new SqlConnection(conString);
SqlCommand com = new SqlCommand("INSERT INTO dbo.Test_db (pf, loan) VALUES (@param1, @param2)", con);
command.Parameters.AddWithValue("@param1", g1.Cells[0].Text);
command.Parameters.AddWithValue("@param2", g1.Cells[1].Text);
con.Open();
com.ExecuteNonQuery();
con.Close();

if you arent seeing an error, is it possible your sql is working but you are simply inserting null or emtpy data into your table?

Edited by JorgeM

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.