Murray Brown
asked on
ASP.net GridView not populating
Hi
I am using the following code to try and populate a GridView in ASP.net but nothing is coming through. I pretty much copied most of it from a VB.net Windows Form application where it retrieved the data fine. Is it perhaps my syntax?
hanks
Sub DisplayContacts()
Dim sqlConn As New SqlClient.SqlConnection
sqlConn.ConnectionString = ConfigurationManager.Conne ctionStrin gs("GHBCRM _TSTConnec tionString ").Connect ionString
Try
sqlConn.Open()
Catch ex As Exception
MsgBox(ex.Message, "connection failed")
End Try
Dim sqlComm As New SqlClient.SqlCommand
sqlComm.Connection = sqlConn
sqlComm.CommandType = CommandType.StoredProcedur e
sqlComm.CommandText = "spViewContacts"
'sqlComm.CommandText = "spViewInvestorsInInvestme nts"
strView = "All Contacts"
sqlComm.Parameters.AddWith Value("@Vi ew", strView)
sqlComm.Parameters.AddWith Value("@RM ", strUserName)
sqlComm.Parameters.AddWith Value("@Se arch", "")
sqlComm.ExecuteNonQuery()
da.SelectCommand = sqlComm
Try
If ds.Tables.IndexOf("tblCont acts") > -1 Then
ds.Tables("tblContacts").C lear()
End If
da.Fill(ds, "tblContacts")
GridView1.DataSource = ds
GridView1.DataMember = "tblContacts"
'GridView1.Columns("contac tid").Visi ble = False
'GridView1.Columns(8).Visi ble = False
'DisplayContactNotes(-1) 'Clear notes datagridview
'lblStatus.Text = ds.Tables("tblContacts").R ows.Count. ToString & " Items"
Catch
End Try
sqlConn.Close()
End Sub
I am using the following code to try and populate a GridView in ASP.net but nothing is coming through. I pretty much copied most of it from a VB.net Windows Form application where it retrieved the data fine. Is it perhaps my syntax?
hanks
Sub DisplayContacts()
Dim sqlConn As New SqlClient.SqlConnection
sqlConn.ConnectionString = ConfigurationManager.Conne
Try
sqlConn.Open()
Catch ex As Exception
MsgBox(ex.Message, "connection failed")
End Try
Dim sqlComm As New SqlClient.SqlCommand
sqlComm.Connection = sqlConn
sqlComm.CommandType = CommandType.StoredProcedur
sqlComm.CommandText = "spViewContacts"
'sqlComm.CommandText = "spViewInvestorsInInvestme
strView = "All Contacts"
sqlComm.Parameters.AddWith
sqlComm.Parameters.AddWith
sqlComm.Parameters.AddWith
sqlComm.ExecuteNonQuery()
da.SelectCommand = sqlComm
Try
If ds.Tables.IndexOf("tblCont
ds.Tables("tblContacts").C
End If
da.Fill(ds, "tblContacts")
GridView1.DataSource = ds
GridView1.DataMember = "tblContacts"
'GridView1.Columns("contac
'GridView1.Columns(8).Visi
'DisplayContactNotes(-1) 'Clear notes datagridview
'lblStatus.Text = ds.Tables("tblContacts").R
Catch
End Try
sqlConn.Close()
End Sub
Where are you declaring the variable strView?
What is the error you are getting?
ASKER
I'm declaring it at the top of the page. I am getting no error
It's hard to tell without seeing all of the code. I don't see where you are creating your dataset (ds). I would add debug="true" in your page declaration and check SQL Profiler to see what parameter values are being passed to your database.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks, that worked