Click here to Skip to main content
15,904,822 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
plz suggest me easy coding as i m starter so will be easy for me to understand for insertand update in gridview.

[edit]SHOUTING removed - OriginalGriff[/edit]
Posted
Updated 6-Mar-13 20:56pm
v4
Comments
OriginalGriff 7-Mar-13 2:54am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.

Insert:
C#
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2)", con))
        {
        com.Parameters.AddWithValue("@C1", myValueForColumn1);
        com.Parameters.AddWithValue("@C2", myValueForColumn2);
        com.ExecuteNonQuery();
        }
    }
Update:
C#
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("UPDATE myTable SET myColumn1=@C1, myColumn2=@C2 WHERE Id=@ID", con))
        {
        com.Parameters.AddWithValue("@ID", id);
        com.Parameters.AddWithValue("@C1", myValueForColumn1);
        com.Parameters.AddWithValue("@C2", myValueForColumn2);
        com.ExecuteNonQuery();
        }
    }
 
Share this answer
 
Comments
Maciej Los 7-Mar-13 3:23am    
OriginalGriff,
Ideed, it isn't code for "insert and update in griview" (whatever it means), but it's simple example how to insert and update data in database ;)
+5!
OriginalGriff 7-Mar-13 3:27am    
He added the Gridview bit after I posted my response!
Maciej Los 7-Mar-13 3:35am    
I know, that's why i posted my comment with ";)"
 
Share this answer
 
Comments
Maciej Los 7-Mar-13 3:34am    
Nice collection of links ;)
+5
__TR__ 7-Mar-13 4:19am    
Thank you :)

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