How to insert dynamic values in database?

Posted by Hariinakoti under VB.NET on 1/4/2013 | Points: 10 | Views : 880 | Status : [Member] | Replies : 1
Hi All,
Iam creating datarows and show that values in gridview.Now i want to save that values in database.
This is my code:
I called this below function in button click.

Protected Sub BindGridviewData()
Dim dt As New DataTable()
dt.Columns.Add("UserId", GetType(Int32))
dt.Columns.Add("FirstName", GetType(String))
dt.Columns.Add("LastName", GetType(String))
dt.Columns.Add("Education", GetType(String))
dt.Columns.Add("Location", GetType(String))
dt.Columns.Add("State", GetType(String))
dt.Columns.Add("MobileNo", GetType(Long))
Dim dtrow As DataRow = dt.NewRow()
dtrow("UserId") = 1
dtrow("FirstName") = "Hari"
dtrow("LastName") = "I"
dtrow("Education") = "MCA"
dtrow("Location") = "Vizianagaram"
dtrow("State") = "AndhraPradesh"
dtrow("MobileNo") = 9966246869
dt.Rows.Add(dtrow)
dtrow = dt.NewRow()
dtrow("UserId") = 2
dtrow("FirstName") = "Vishak"
dtrow("LastName") = "Nair"
dtrow("Education") = "BCA"
dtrow("Location") = "Kochi"
dtrow("State") = "Kerala"
dtrow("MobileNo") = 8886355702
dt.Rows.Add(dtrow)
dtrow = dt.NewRow()
dtrow("UserId") = 3
dtrow("FirstName") = "Samba"
dtrow("LastName") = "Nallamala"
dtrow("Education") = "B.Tech"
dtrow("Location") = "Tirupathi"
dtrow("State") = "AndhraPradesh"
dtrow("MobileNo") = 9954786688
dt.Rows.Add(dtrow)
dtrow = dt.NewRow()
dtrow("UserId") = 4
dtrow("FirstName") = "Venkat"
dtrow("LastName") = "K"
dtrow("Education") = "B.Tech"
dtrow("Location") = "Hyderabad"
dtrow("State") = "AndhraPradesh"
dtrow("MobileNo") = 7356588688
dt.Rows.Add(dtrow)
editgrid.DataSource = dt
editgrid.DataBind()
End Sub

Thanks & Regards
Hari



Responses

Posted by: Naraayanan on: 1/4/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,
Get Row Count of Gridview .
use For Loop .
Call Your Store Procedure or Insert Statement.


Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Hariinakoti, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response