shanebrennan1968
Programmer
I'm hitting a stone wall and I hope someone can help me please. Please forgive me for any terminology I will undoubtly get wrong.
I have created a DataSet to a SQL Express server and have managed to Bind this dataset to a FormView in EditMode to allow me to edit the date. For this screen I don't want to use the built in update functions, as I will have a number of Multiselect Listboxes on the form view that I need to set and unset during the page load and update tasks.
Anyways My problem is, when I come to update the DataSet I'm hitting a "NullReferenceException was unhandled by user code" error. on the following line in the cmdUpdate_Click event:
MyDataSet.Tables("tblClients").Rows(0)("Name") = MyTextBox.Text
The MyTEstBox.text does indeed contain text from the TextBox control "Name" on the FormView.
The problems is the DataSet "MyDataSet" is completely and utterly empty! even though I used it on the PageLoad.
I know I am missing something simple but I can't figger it out - please help.
Thank you in advance of any help given.
Shane Brennan
My Code
/---------
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Data
Partial Class Clients_ClientDetails4
Inherits System.Web.UI.Page
Dim MySqlDataAdapter As SqlDataAdapter
Dim MyDataSet As DataSet = New DataSet()
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
Dim CustomerID As Integer
CustomerID = Request("ID")
If IsPostBack Then
' do nothing
Else
Dim ConnectionString As String = ConfigurationManager.ConnectionStrings("FRAConnectionString").ToString
Dim SQLStr As String = "Select * from tblClients where ID=" & CustomerID & ";"
Dim MysqlConnection As SqlConnection
MysqlConnection = New SqlConnection(ConnectionString)
MySqlDataAdapter = New SqlDataAdapter(SQLStr, MysqlConnection)
Dim MyDataRowsCommandBuilder As SqlCommandBuilder = New SqlCommandBuilder(MySqlDataAdapter)
MySqlDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
MySqlDataAdapter.Fill(MyDataSet, "tblClients")
FormView1.DataSource = MyDataSet
FormView1.DataBind()
End If
End Sub
Protected Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim MyTextBox As TextBox
MyTextBox = FormView1.FindControl("Name")
MyDataSet.Tables("tblClients").Rows(0)("Name") = MyTextBox.Text
MySqlDataAdapter.Update(MyDataSet, "tblClients")
End Sub
Protected Sub cmdCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
End Class
I have created a DataSet to a SQL Express server and have managed to Bind this dataset to a FormView in EditMode to allow me to edit the date. For this screen I don't want to use the built in update functions, as I will have a number of Multiselect Listboxes on the form view that I need to set and unset during the page load and update tasks.
Anyways My problem is, when I come to update the DataSet I'm hitting a "NullReferenceException was unhandled by user code" error. on the following line in the cmdUpdate_Click event:
MyDataSet.Tables("tblClients").Rows(0)("Name") = MyTextBox.Text
The MyTEstBox.text does indeed contain text from the TextBox control "Name" on the FormView.
The problems is the DataSet "MyDataSet" is completely and utterly empty! even though I used it on the PageLoad.
I know I am missing something simple but I can't figger it out - please help.
Thank you in advance of any help given.
Shane Brennan
My Code
/---------
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Data
Partial Class Clients_ClientDetails4
Inherits System.Web.UI.Page
Dim MySqlDataAdapter As SqlDataAdapter
Dim MyDataSet As DataSet = New DataSet()
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
Dim CustomerID As Integer
CustomerID = Request("ID")
If IsPostBack Then
' do nothing
Else
Dim ConnectionString As String = ConfigurationManager.ConnectionStrings("FRAConnectionString").ToString
Dim SQLStr As String = "Select * from tblClients where ID=" & CustomerID & ";"
Dim MysqlConnection As SqlConnection
MysqlConnection = New SqlConnection(ConnectionString)
MySqlDataAdapter = New SqlDataAdapter(SQLStr, MysqlConnection)
Dim MyDataRowsCommandBuilder As SqlCommandBuilder = New SqlCommandBuilder(MySqlDataAdapter)
MySqlDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
MySqlDataAdapter.Fill(MyDataSet, "tblClients")
FormView1.DataSource = MyDataSet
FormView1.DataBind()
End If
End Sub
Protected Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim MyTextBox As TextBox
MyTextBox = FormView1.FindControl("Name")
MyDataSet.Tables("tblClients").Rows(0)("Name") = MyTextBox.Text
MySqlDataAdapter.Update(MyDataSet, "tblClients")
End Sub
Protected Sub cmdCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
End Class