Showing posts with label table. Show all posts
Showing posts with label table. Show all posts

Saturday, March 31, 2012

There is no row at position 0??

Can someone please tell me why I keep getting the error!
There is no row at position 0
Dim row As DataRow = table.Rows(0)
I know it has something to do with the value of rowID because if I set rowID
as a fixed value rather than using a querystring it works!
Any ideas?
Thanks
Private rowID As Integer
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Get Text for Editor
If Not Page.IsPostBack Then
FreeTextBox1.Text = GetDocument()
End If
rowID = Request.QueryString(ID)
End Sub 'Page_Load
Public Sub Button_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
UpdateDocument(FreeTextBox1.Text)
End Sub 'Button_Click
Private Function GetDocument() As String
Dim ds As DataSet = GetDataSet(("SELECT * FROM tblPageContent WHERE
pageID=" + rowID.ToString()))
Dim table As DataTable = ds.Tables(0)
Dim row As DataRow = table.Rows(0)
Dim doc As String = row("content").ToString()
Return doc
End Function 'GetDocumenthat code looks like the FreeTextBox code at
http://www.freetextbox.com/forums/S...aspx?PostID=613
You might want to compare your version of that code
with the published version at that page, which works,
and see where you made a transcription or conceptual
mistake.
Offhand, I see that DonnyEMU declared
Private rowID As Integer = 1
so that there wouldn't be a reference
to an empty row in the initial call.
Juan T. Llibre
ASP.NET MVP
===========
"Tim::.." <myatix_at_hotmail.com> wrote in message
news:67A134C0-4AE9-408E-A871-2DBA408A192E@.microsoft.com...
> Can someone please tell me why I keep getting the error!
> There is no row at position 0
> Dim row As DataRow = table.Rows(0)
> I know it has something to do with the value of rowID because if I set
> rowID
> as a fixed value rather than using a querystring it works!
> Any ideas?
> Thanks
> Private rowID As Integer
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> 'Get Text for Editor
> If Not Page.IsPostBack Then
> FreeTextBox1.Text = GetDocument()
> End If
> rowID = Request.QueryString(ID)
> End Sub 'Page_Load
> Public Sub Button_Click(ByVal sender As Object, ByVal e As
> System.EventArgs)
> UpdateDocument(FreeTextBox1.Text)
> End Sub 'Button_Click
> Private Function GetDocument() As String
> Dim ds As DataSet = GetDataSet(("SELECT * FROM tblPageContent WHERE
> pageID=" + rowID.ToString()))
> Dim table As DataTable = ds.Tables(0)
> Dim row As DataRow = table.Rows(0)
> Dim doc As String = row("content").ToString()
> Return doc
> End Function 'GetDocument
re:
> so that there wouldn't be a reference
> to an empty row in the initial call.
Oops...that should be :

> so that there wouldn't be a reference
> to a non-existent row in the initial call.
Juan T. Llibre
ASP.NET MVP
===========
"Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in message
news:udLVWM7AFHA.3416@.TK2MSFTNGP09.phx.gbl...
> hat code looks like the FreeTextBox code at
> http://www.freetextbox.com/forums/S...aspx?PostID=613
> You might want to compare your version of that code
> with the published version at that page, which works,
> and see where you made a transcription or conceptual
> mistake.
> Offhand, I see that DonnyEMU declared
> Private rowID As Integer = 1
> so that there wouldn't be a reference
> to an empty row in the initial call.
>
>
> Juan T. Llibre
> ASP.NET MVP
> ===========
> "Tim::.." <myatix_at_hotmail.com> wrote in message
> news:67A134C0-4AE9-408E-A871-2DBA408A192E@.microsoft.com...
>
You are calling GetDocument before you assign rowID. So rowID is always 0
when this function gets called, and your query does not return a result.
"Tim::.." <myatix_at_hotmail.com> wrote in message
news:67A134C0-4AE9-408E-A871-2DBA408A192E@.microsoft.com...
> Can someone please tell me why I keep getting the error!
> There is no row at position 0
> Dim row As DataRow = table.Rows(0)
> I know it has something to do with the value of rowID because if I set
> rowID
> as a fixed value rather than using a querystring it works!
> Any ideas?
> Thanks
> Private rowID As Integer
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> 'Get Text for Editor
> If Not Page.IsPostBack Then
> FreeTextBox1.Text = GetDocument()
> End If
> rowID = Request.QueryString(ID)
> End Sub 'Page_Load
> Public Sub Button_Click(ByVal sender As Object, ByVal e As
> System.EventArgs)
> UpdateDocument(FreeTextBox1.Text)
> End Sub 'Button_Click
> Private Function GetDocument() As String
> Dim ds As DataSet = GetDataSet(("SELECT * FROM tblPageContent WHERE
> pageID=" + rowID.ToString()))
> Dim table As DataTable = ds.Tables(0)
> Dim row As DataRow = table.Rows(0)
> Dim doc As String = row("content").ToString()
> Return doc
> End Function 'GetDocument

There is no row at position 0??

Can someone please tell me why I keep getting the error!

There is no row at position 0
Dim row As DataRow = table.Rows(0)

I know it has something to do with the value of rowID because if I set rowID
as a fixed value rather than using a querystring it works!

Any ideas?

Thanks

Private rowID As Integer

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Get Text for Editor
If Not Page.IsPostBack Then
FreeTextBox1.Text = GetDocument()
End If
rowID = Request.QueryString(ID)
End Sub 'Page_Load

Public Sub Button_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
UpdateDocument(FreeTextBox1.Text)
End Sub 'Button_Click

Private Function GetDocument() As String
Dim ds As DataSet = GetDataSet(("SELECT * FROM tblPageContent WHERE
pageID=" + rowID.ToString()))
Dim table As DataTable = ds.Tables(0)
Dim row As DataRow = table.Rows(0)
Dim doc As String = row("content").ToString()
Return doc
End Function 'GetDocumenthat code looks like the FreeTextBox code at
http://www.freetextbox.com/forums/S...aspx?PostID=613

You might want to compare your version of that code
with the published version at that page, which works,
and see where you made a transcription or conceptual
mistake.

Offhand, I see that DonnyEMU declared

Private rowID As Integer = 1

so that there wouldn't be a reference
to an empty row in the initial call.

Juan T. Llibre
ASP.NET MVP
===========
"Tim::.." <myatix_at_hotmail.com> wrote in message
news:67A134C0-4AE9-408E-A871-2DBA408A192E@.microsoft.com...
> Can someone please tell me why I keep getting the error!
> There is no row at position 0
> Dim row As DataRow = table.Rows(0)
> I know it has something to do with the value of rowID because if I set
> rowID
> as a fixed value rather than using a querystring it works!
> Any ideas?
> Thanks
> Private rowID As Integer
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> 'Get Text for Editor
> If Not Page.IsPostBack Then
> FreeTextBox1.Text = GetDocument()
> End If
> rowID = Request.QueryString(ID)
> End Sub 'Page_Load
> Public Sub Button_Click(ByVal sender As Object, ByVal e As
> System.EventArgs)
> UpdateDocument(FreeTextBox1.Text)
> End Sub 'Button_Click
> Private Function GetDocument() As String
> Dim ds As DataSet = GetDataSet(("SELECT * FROM tblPageContent WHERE
> pageID=" + rowID.ToString()))
> Dim table As DataTable = ds.Tables(0)
> Dim row As DataRow = table.Rows(0)
> Dim doc As String = row("content").ToString()
> Return doc
> End Function 'GetDocument
re:
> so that there wouldn't be a reference
> to an empty row in the initial call.

Oops...that should be :

> so that there wouldn't be a reference
> to a non-existent row in the initial call.

Juan T. Llibre
ASP.NET MVP
===========
"Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in message
news:udLVWM7AFHA.3416@.TK2MSFTNGP09.phx.gbl...
> hat code looks like the FreeTextBox code at
> http://www.freetextbox.com/forums/S...aspx?PostID=613
> You might want to compare your version of that code
> with the published version at that page, which works,
> and see where you made a transcription or conceptual
> mistake.
> Offhand, I see that DonnyEMU declared
> Private rowID As Integer = 1
> so that there wouldn't be a reference
> to an empty row in the initial call.
>
>
> Juan T. Llibre
> ASP.NET MVP
> ===========
> "Tim::.." <myatix_at_hotmail.com> wrote in message
> news:67A134C0-4AE9-408E-A871-2DBA408A192E@.microsoft.com...
>> Can someone please tell me why I keep getting the error!
>>
>> There is no row at position 0
>> Dim row As DataRow = table.Rows(0)
>>
>> I know it has something to do with the value of rowID because if I set
>> rowID
>> as a fixed value rather than using a querystring it works!
>>
>> Any ideas?
>>
>> Thanks
>>
>> Private rowID As Integer
>>
>> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles MyBase.Load
>>
>> 'Get Text for Editor
>> If Not Page.IsPostBack Then
>> FreeTextBox1.Text = GetDocument()
>> End If
>> rowID = Request.QueryString(ID)
>> End Sub 'Page_Load
>>
>> Public Sub Button_Click(ByVal sender As Object, ByVal e As
>> System.EventArgs)
>> UpdateDocument(FreeTextBox1.Text)
>> End Sub 'Button_Click
>>
>> Private Function GetDocument() As String
>> Dim ds As DataSet = GetDataSet(("SELECT * FROM tblPageContent
>> WHERE
>> pageID=" + rowID.ToString()))
>> Dim table As DataTable = ds.Tables(0)
>> Dim row As DataRow = table.Rows(0)
>> Dim doc As String = row("content").ToString()
>> Return doc
>> End Function 'GetDocument
You are calling GetDocument before you assign rowID. So rowID is always 0
when this function gets called, and your query does not return a result.

"Tim::.." <myatix_at_hotmail.com> wrote in message
news:67A134C0-4AE9-408E-A871-2DBA408A192E@.microsoft.com...
> Can someone please tell me why I keep getting the error!
> There is no row at position 0
> Dim row As DataRow = table.Rows(0)
> I know it has something to do with the value of rowID because if I set
> rowID
> as a fixed value rather than using a querystring it works!
> Any ideas?
> Thanks
> Private rowID As Integer
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> 'Get Text for Editor
> If Not Page.IsPostBack Then
> FreeTextBox1.Text = GetDocument()
> End If
> rowID = Request.QueryString(ID)
> End Sub 'Page_Load
> Public Sub Button_Click(ByVal sender As Object, ByVal e As
> System.EventArgs)
> UpdateDocument(FreeTextBox1.Text)
> End Sub 'Button_Click
> Private Function GetDocument() As String
> Dim ds As DataSet = GetDataSet(("SELECT * FROM tblPageContent WHERE
> pageID=" + rowID.ToString()))
> Dim table As DataTable = ds.Tables(0)
> Dim row As DataRow = table.Rows(0)
> Dim doc As String = row("content").ToString()
> Return doc
> End Function 'GetDocument

Wednesday, March 28, 2012

This Dataset is going to be the death of me! Please Help

I am trying to update a database table through this dataset. The error is
ambigous: "System.NullReferenceException: Object reference not set to an
instance of an object." I have tried replacing the variable "month" with a
string and I tried replacing "ProductList.ToString()" with a string but I
still get the error:

Me.sqlDataAdapter1.Fill(DataSet1, "Queue")

Dim QueueRow As DataRow
QueueRow = DataSet1.Tables("Queue").Rows.Find(myCustomerID)
>>ERROR HERE<< QueueRow(month) = ProductList.ToString()

Me.sqlDataAdapter1.Update(DataSet1, "Queue")

Please Help!

Thanks, Justin.Justin wrote:
> (abridged) I have tried replacing the variable "month" with a
> string and I tried replacing "ProductList.ToString()" with a string but I
> still get the error:
What is the value of the month variable? It looks as if you're trying to
change the value of the "month" column in the DataRow. If so you must
place quotes around the word "month". Like this:
QueueRow("month") = ProductList.ToString()

Anders Nor?s
http://dotnetjunkies.com/weblog/anoras
month is a string variable representing a table column to save the data to, I
have tried replacing this with a static column string but I still get the
same error.

"Anders Nor?s" wrote:

> Justin wrote:
> > (abridged) I have tried replacing the variable "month" with a
> > string and I tried replacing "ProductList.ToString()" with a string but I
> > still get the error:
> What is the value of the month variable? It looks as if you're trying to
> change the value of the "month" column in the DataRow. If so you must
> place quotes around the word "month". Like this:
> QueueRow("month") = ProductList.ToString()
> Anders Nor?s
> http://dotnetjunkies.com/weblog/anoras
Justin wrote:
> month is a string variable representing a table column to save the data to, I
> have tried replacing this with a static column string but I still get the
> same error.
Ok, then I suspect that the statement
DataSet1.Tables("Queue").Rows.Find(myCustomerID) evaluates to null. If
this is the case, the ensuing statement will cause an
NullReferenceException. You can place an assertion in your code to
display a message if the QueueRow is null.

The following statement check whether QueueRow is null and outputs a
message if it is:
Debug.Assert( Not (QueueRow Is Nothing), "QueueRow parameter is null",
"Can't get object for null type")

Anders Nor?s
http://dotnetjunkies.com/weblog/anoras/

This Dataset is going to be the death of me! Please Help

I am trying to update a database table through this dataset. The error is
ambigous: "System.NullReferenceException: Object reference not set to an
instance of an object." I have tried replacing the variable "month" with a
string and I tried replacing "ProductList.ToString()" with a string but I
still get the error:
Me.sqlDataAdapter1.Fill(DataSet1, "Queue")
Dim QueueRow As DataRow
QueueRow = DataSet1.Tables("Queue").Rows.Find(myCustomerID)
Me.sqlDataAdapter1.Update(DataSet1, "Queue")
Please Help!
Thanks, Justin.Justin wrote:
> (abridged) I have tried replacing the variable "month" with a
> string and I tried replacing "ProductList.ToString()" with a string but I
> still get the error:
What is the value of the month variable? It looks as if you're trying to
change the value of the "month" column in the DataRow. If so you must
place quotes around the word "month". Like this:
QueueRow("month") = ProductList.ToString()
Anders Nor?s
http://dotnetjunkies.com/weblog/anoras
month is a string variable representing a table column to save the data to,
I
have tried replacing this with a static column string but I still get the
same error.
"Anders Nor?s" wrote:

> Justin wrote:
> What is the value of the month variable? It looks as if you're trying to
> change the value of the "month" column in the DataRow. If so you must
> place quotes around the word "month". Like this:
> QueueRow("month") = ProductList.ToString()
> Anders Nor?s
> http://dotnetjunkies.com/weblog/anoras
>
Justin wrote:
> month is a string variable representing a table column to save the data to
, I
> have tried replacing this with a static column string but I still get the
> same error.
Ok, then I suspect that the statement
DataSet1.Tables("Queue").Rows.Find(myCustomerID) evaluates to null. If
this is the case, the ensuing statement will cause an
NullReferenceException. You can place an assertion in your code to
display a message if the QueueRow is null.
The following statement check whether QueueRow is null and outputs a
message if it is:
Debug.Assert( Not (QueueRow Is Nothing), "QueueRow parameter is null",
"Can't get object for null type")
Anders Nor?s
http://dotnetjunkies.com/weblog/anoras/

Monday, March 26, 2012

This is driving me nuts

Ok, the weblog is still giving some problems. My database table fields are set to not allow nulls but I'm stil able to insert data into the fields. Now everything works fine on my computer but craps up when I upload the project.
I need some help.I think I'm going to just host my weblog on my on computer at home. EhostingBiz.com, is just not doing it for me. I create my tables and set the columns to not null, but they still allow null values. Everything works on my computer, so I know its not my code. I'm going to bed now.
Have you tried another host - a free one just to compare whether its your current.
No, I have not tried another host. Thats gonna take too much time.
All I wanna know is. How is it possible to insert null values in columns that are set to not allow null values.
Its not possible - except you can add checks which only apply to new data ignoring previous rows but cannot recall if this can apply to nullability!!!
I can't believe this can happen against the way SQL Server works.
Can you post you tabel schema?
I would bet that it might be a database setting that is doing this for you. I would go to the database forum and ask why this isn't working like you want it.

I always verify the data I am throwing at the database anyway, I can usually head off reads and writes that won't work based on the rules I have set. This first acts like a filter, and also as a performance enhancement because you don't have to needlessly access the database unless you are 95% sure the data is good.

If I have time today, I will check into whether or not I can do this on my DB.

Also, it would be helpful if you generated a setup script of you database and posted it here. We might be able to find a problem in there.
Originally posted by hellswraith
I would bet that it might be a database setting that is doing this for you. I would go to the database forum and ask why this isn't working like you want it.

I always verify the data I am throwing at the database anyway, I can usually head off reads and writes that won't work based on the rules I have set. This first acts like a filter, and also as a performance enhancement because you don't have to needlessly access the database unless you are 95% sure the data is good.

If I have time today, I will check into whether or not I can do this on my DB.

Also, it would be helpful if you generated a setup script of you database and posted it here. We might be able to find a problem in there.

I think thats what is happening. Another problem I have is that my RequiredValidator controls wont fire when I upload my project. As I've said before everything works fine on my computer, so this is kinda strange. To force the RequiredValidators to fire, I had to put my code in an if(Page.IsValid) block. I did'nt really want to do that since the page is posting back.

Here is the script.
If you select NO to allow nulls then you will have to supply data to be inserted into the field when a record is inserted. If you have no data to populate the field then sometimes an empty string will do.

But the easiest way I have found is to supply a default value for the field. For string fields and empty string will do. For numerics a zero. For date fields you can use GetDate() as the default or supply a non-sense date like '01-01-1900'.

And a null is a null is nothing...
Should'nt the DB throw an exception if the value is null? If I enter data from enterprise manager and leave a column empty, an exception is thrown.
OK, I am not sure what columns your having problems with. Here is what I see from the scripts...
URL and Email in the comments table are set to ALLOW null values. If these are the columns that are giving you trouble, then you need to switch them to Not Null.

Another thing I have found with ASP.Net is that a empty text box will return a empty string instead of a null value if there is nothing in it. You may be allowed to enter the data because the empty string is being passed therefore it isn't really a null value.
Originally posted by hellswraith
OK, I am not sure what columns your having problems with. Here is what I see from the scripts...
URL and Email in the comments table are set to ALLOW null values. If these are the columns that are giving you trouble, then you need to switch them to Not Null.

Another thing I have found with ASP.Net is that a empty text box will return a empty string instead of a null value if there is nothing in it. You may be allowed to enter the data because the empty string is being passed therefore it isn't really a null value.

The url and email columns are suppose to be like that. I'll have to check out what you said about the empty text box. Thanks for help.