D
denis
Hello I'm trying to run this code but i get an error:
"Object reference not set to an instance of an object. "
Can somebody help me?
Thanks
Try
'***************************************************************************
********
objTransact = objConnection.BeginTransaction()
'***************************************************************************
********
strSQL = "INSERT INTO Artisti (a_nome) values ('pippo')"
myDataAdapter = New OleDbDataAdapter( strSQL, objConnection )
myDataAdapter.InsertCommand.Transaction = objTransact
myDataSet = New DataSet()
myDataAdapter.Fill( myDataSet, "Artisti")
myDataTable = myDataSet.Tables("Artisti")
'Crea u datarow con il record da inserire
myDataRow = myDataTable.NewRow()
myDataRow("a_nome") = Request.Form("NOME")
myDataRow("a_cognome") = Request.Form("COGNOME")
myDataRow("a_usr") = Request.Form("USR")
myDataRow("a_pwd") = Request.Form("PWD")
myDataRow("a_azienda") = Request.Form("AZIENDA")
myDataRow("a_indirizzo") = Request.Form("INDIRIZZO")
myDataRow("a_cap") = Request.Form("CAP")
myDataTable.Rows.Add(myDataRow)
DBCommandBuilder = New OleDbCommandBuilder(myDataAdapter)
myDataAdapter.InsertCommand = DBCommandBuilder.GetInsertCommand()
myDataAdapter.Update(myDataSet, "Artisti")
objTransact.Commit()
catch ex as exception
lblStatus.Text += "Error:<br>" & ex.Message
objTransact.Rollback()
Finally
objConnection.Close()
End try
"Object reference not set to an instance of an object. "
Can somebody help me?
Thanks
Try
'***************************************************************************
********
objTransact = objConnection.BeginTransaction()
'***************************************************************************
********
strSQL = "INSERT INTO Artisti (a_nome) values ('pippo')"
myDataAdapter = New OleDbDataAdapter( strSQL, objConnection )
myDataAdapter.InsertCommand.Transaction = objTransact
myDataSet = New DataSet()
myDataAdapter.Fill( myDataSet, "Artisti")
myDataTable = myDataSet.Tables("Artisti")
'Crea u datarow con il record da inserire
myDataRow = myDataTable.NewRow()
myDataRow("a_nome") = Request.Form("NOME")
myDataRow("a_cognome") = Request.Form("COGNOME")
myDataRow("a_usr") = Request.Form("USR")
myDataRow("a_pwd") = Request.Form("PWD")
myDataRow("a_azienda") = Request.Form("AZIENDA")
myDataRow("a_indirizzo") = Request.Form("INDIRIZZO")
myDataRow("a_cap") = Request.Form("CAP")
myDataTable.Rows.Add(myDataRow)
DBCommandBuilder = New OleDbCommandBuilder(myDataAdapter)
myDataAdapter.InsertCommand = DBCommandBuilder.GetInsertCommand()
myDataAdapter.Update(myDataSet, "Artisti")
objTransact.Commit()
catch ex as exception
lblStatus.Text += "Error:<br>" & ex.Message
objTransact.Rollback()
Finally
objConnection.Close()
End try