.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> VB.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Gridview not binding from stored procedure

Posted By: Catherine     Posted Date: April 09, 2011    Points:5   Category :VB.Net
Thank you all works well. i am using gridview not binding data from stored procedure. but same data worked in sql query not work in vb.net

here is my code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

connectionString = ""
Dim connection As OleDbConnection = New leDbConnection(connectionString)
If Not Page.IsPostBack Then
connection.Open()
SQLstr = "SELECT strbranchname from tblbranch"
Dim da As OleDbDataAdapter = New OleDbDataAdapter(SQLstr, connection)
Dim ds As New DataSet()
da.Fill(ds)
ddlbranch.DataSource = ds
ddlbranch.DataTextField = "strbranchname"
'ddlbranch.DataValueField = "strbranchcode"
ddlbranch.DataBind()
ddlbranch.Items.Insert(0, New ListItem("Select"))
ddltype.Items.Insert(0, New ListItem("Select"))
ddltype.Items.Add("Sales")
ddltype.Items.Add("Encashment")
ddltype.DataValueField = "type"
connection.Close()
End If


End Sub

Dim connection As OleDbConnection = New OleDbConnection(connectionString)
Dim strtodate As String
Dim strfromdate As String
Dim strbrname As String
Dim strtype As String

strbrname = ddlbranch.SelectedItem.Text
strtype = ddltype.SelectedItem.Text
strfromdate = txtfdate.Text
strtodate = txttdate.Text

Dim cmd As New OleDbCommand("sp_Encash", connection)
' cmd.CommandType = CommandType.Text
cmd.CommandType = CommandType.StoredProcedure
Dim pstrbranchname As New OleDbParameter("@strbranchname", OleDbType.VarChar, 20)
ddlbranch.DataValueField = Convert.ToString(pstrbranchname)
Dim pfromdate As New OleDbParameter("@fromdate", OleDbType.VarChar, 20)
' txtfdate.Text = Convert.ToString(pfromdate)
Dim ptodate As New OleDbParameter("@todate", OleDbType.VarChar, 20)
' txttdate.Text = Convert.ToString(ptodate)
Dim ptype As New OleDbParameter("@type", OleDbType.VarChar, 10)
ddltype.DataValueField = Convert.ToString(ptype)
pstrbranchname.Value = strbrname
ptype.Value = strtype
ptodate.Value = strtodate
pfromdate.Value = strfromdate
cmd.Parameters.Add(pstrbranchname)
cmd.Parameters.Add(ptype)
cmd.Parameters.Add(ptodate)
cmd.Parameters.Add(pfromdate)
connection.Open()
Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds)
GridView1.DataSource = ds
GridView1.DataBind()
connection.Close()
End Sub


Responses
Author: Maverick             
Posted Date: April 11, 2011     Points: 20   

Hello,

Please check the column name of the grid and the binding dataset they must be same. Does the your dataset have some data to bind after the sp is executed.

Thanks,
Maverick

Thanks,
Maverick


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend