i need to populate a gridview control inside a click event:
this is my code, it does not work, why?
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
Dim conn As New Data.OleDb.OleDbConnection
Dim cmd As New Data.OleDb.OleDbCommand
conn = New Data.OleDb.OleDbConnection("Provider=SQLOLEDB.1;Password=**********;Persist Security Info=True;User ID=***;Initial Catalog=Mango2Telemarketing;Data Source=4G")
conn.Open()
cmd = New Data.OleDb.OleDbCommand("select field1, field2, field3.... from Table1 ", conn)
Dim dt As New Data.OleDb.OleDbDataReader
dt = cmd.ExecuteScalar
GridView1.DataBind()
End Sub
JFRBPH12™
It's more fun in the Philippines :)
http://www.itsmorefuninthephilippines.com/
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question
Hi, i have done the added code but the gridview did not populate any data??
please help??
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
Dim conn As New Data.OleDb.OleDbConnection
Dim cmd As New Data.OleDb.OleDbCommand
conn = New Data.OleDb.OleDbConnection("Provider=SQLOLEDB.1;Password=**********;Persist Security Info=True;User ID=***;Initial Catalog=Mango2Telemarketing;Data Source=4G")
conn.Open()
cmd = New Data.OleDb.OleDbCommand("select field1, field2, field3.... from Table1 ", conn)
Dim dt As New Data.OleDb.OleDbDataAdapter
dt = cmd.ExecuteScalar
GridView1.DataSource = dt
End Sub
JFRBPH12™
It's more fun in the Philippines :)
http://www.itsmorefuninthephilippines.com/
Dim dt
As New Data.OleDb.OleDbDataAdapter
dt = cmd.ExecuteScalar
GridView1.DataSource = dt
change it to :
Dim dt
As New Data.OleDb.OleDbDataReader
dt = cmd.ExecuteReader(CommandBehavior.CloseConnection)
GridView1.DataSource = dt
Samu Zhang
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
Marked as answer by johnjalani on Oct 17, 2008 01:34 AM
johnjalani
Member
334 Points
554 Posts
Hoe to populate Gridview using VB.NET
Oct 10, 2008 08:19 AM|LINK
Hi.,Please help me,
i need to populate a gridview control inside a click event:
this is my code, it does not work, why?
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click Dim conn As New Data.OleDb.OleDbConnection Dim cmd As New Data.OleDb.OleDbCommand conn = New Data.OleDb.OleDbConnection("Provider=SQLOLEDB.1;Password=**********;Persist Security Info=True;User ID=***;Initial Catalog=Mango2Telemarketing;Data Source=4G") conn.Open() cmd = New Data.OleDb.OleDbCommand("select field1, field2, field3.... from Table1 ", conn) Dim dt As New Data.OleDb.OleDbDataReader dt = cmd.ExecuteScalar GridView1.DataBind() End SubIt's more fun in the Philippines :)
http://www.itsmorefuninthephilippines.com/
sivagan
Member
100 Points
21 Posts
Re: Hoe to populate Gridview using VB.NET
Oct 10, 2008 09:40 AM|LINK
HI
you are missing one line
gridview1.datasource = dt
this should be before bind line
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question
johnjalani
Member
334 Points
554 Posts
Re: Hoe to populate Gridview using VB.NET
Oct 13, 2008 01:13 AM|LINK
Hi, i have done the added code but the gridview did not populate any data??
please help??
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click Dim conn As New Data.OleDb.OleDbConnection Dim cmd As New Data.OleDb.OleDbCommand conn = New Data.OleDb.OleDbConnection("Provider=SQLOLEDB.1;Password=**********;Persist Security Info=True;User ID=***;Initial Catalog=Mango2Telemarketing;Data Source=4G") conn.Open() cmd = New Data.OleDb.OleDbCommand("select field1, field2, field3.... from Table1 ", conn) Dim dt As New Data.OleDb.OleDbDataAdapter dt = cmd.ExecuteScalar GridView1.DataSource = dt End SubIt's more fun in the Philippines :)
http://www.itsmorefuninthephilippines.com/
Samu Zhang -...
All-Star
62163 Points
6101 Posts
Re: Hoe to populate Gridview using VB.NET
Oct 13, 2008 07:20 AM|LINK
Hi johnjalani ,
Dim dt As New Data.OleDb.OleDbDataAdapter
dt = cmd.ExecuteScalar
GridView1.DataSource = dt
change it to :
Dim dt As New Data.OleDb.OleDbDataReader
dt = cmd.ExecuteReader(CommandBehavior.CloseConnection)
GridView1.DataSource = dt
Samu Zhang
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
johnjalani
Member
334 Points
554 Posts
Re: Hoe to populate Gridview using VB.NET
Oct 14, 2008 08:41 AM|LINK
Hi, Thanks for the reply,
i have used the code that you said, it does not show any errors, but the gridview also did not show in the click event??
It's more fun in the Philippines :)
http://www.itsmorefuninthephilippines.com/
Samu Zhang -...
All-Star
62163 Points
6101 Posts
Re: Hoe to populate Gridview using VB.NET
Oct 16, 2008 10:06 AM|LINK
Hi johnjalani ,
Need to call GridView.DataBind();
Samu Zhang
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
johnjalani
Member
334 Points
554 Posts
Re: Hoe to populate Gridview using VB.NET
Oct 17, 2008 01:43 AM|LINK
Hi Samu,
Thanks for the help, your the best. :)
SALAMAT PO., - means thanks with respect in Filipino
It's more fun in the Philippines :)
http://www.itsmorefuninthephilippines.com/