Showing posts with label variable. Show all posts
Showing posts with label variable. Show all posts

Saturday, March 31, 2012

System.IndexOutOfRangeException

Hello,

I have the following code where all the used variable are declared to their respective types:

insertSql = "SELECT Max([Customer ID]) AS CustID FROM [Registration Info]"
objCommand = New OleDbCommand(insertSql, objConn)
objConn.Open()
objDR = objCommand.ExecuteReader()

While objDR.Read()
CustID=objDR("Cust ID") '********** (1.)
End While

I am getting an error on (1.). its says "System.IndexOutOfRangeException: Cust ID" why is this happening? Can comeone help me whith this problem?

Thanks,
~sIf the code enters the while loop then tere are values within objDR so why not add a watch to this and check the value of objDr(0) and then objDR(1)

Hope that helps

Cheers
Gregor Suttie
I would say it is happening because there is no field in the result called "Cust ID", though there is one called "CustID"
Yes i know thats a silly mistake on my part. very silly... i wish i could delete this post. :) thanks very much. now i am doing it like objDR(0)

Regards.

System.Int32 Vs Integer

Hi,

what is the difference b/w variable declaration as Integer and System.Int32

VenuNothing,

they are one and the same. Integer is just VB-specific way to express integer variables and it maps directly to System.Int32.

Thursday, March 22, 2012

System.NullReferenceException: Object variable or With block variable not set

Please help i am getting the following error:
System.NullReferenceException: Object variable or With block variable not set

on this line.


TextBox1.Text = Trim(Row.Item("eng_lbl"))

I am trying to display the values of a record from the table in 4 text box fields.
I am new to asp.net. Please kindly help.


Dim mydataset As New DataSet
Dim myadapter As New SqlDataAdapter
Dim strId As String = Request.QueryString("lbl_Id")
Dim Row

Dim myCommand As New SqlClient.SqlCommand

Dim sql As String = "select * from tbl_labels where id =" & CInt(strId)

If Not Page.IsPostBack Then
MyCommand = New SqlCommand(sql, MyConnection)

myadapter = New SqlDataAdapter(myCommand)

mydataset.Clear()
myadapter.Fill(mydataset)

If mydataset.Tables(0).Rows.Count > 0 Then
TextBox1.Text = Trim(Row.Item("eng_lbl"))
TextBox2.Text = Trim(Row.Item("esp_lbl"))
TextBox3.Text = Trim(Row.Item("fr_lbl"))
TextBox4.Text = Trim(Row.Item("ger_lbl"))
End If
End If

You're not assign row to anything..

I.E.


Dim Row As DataRow

If mydataset.Tables(0).Rows.Count > 0 Then

Row = mydataset.Tables(0).Rows(0)

TextBox1.Text = Trim(Row.Item("eng_lbl"))

TextBox2.Text = Trim(Row.Item("esp_lbl"))

TextBox3.Text = Trim(Row.Item("fr_lbl"))

TextBox4.Text = Trim(Row.Item("ger_lbl"))

End If

System.NullReferenceException: Object variable or With block varia

Hello -

I don't know if it's possible or not, but I am trying to bind data from a
Sql Server DB to the header in a datalist. I received the above error
message.

First, is it possible to bind data from a DB to the header and if so, what
could be causing the error message?

Alternatively, can you only put text in the header of a datalist?
--
SandySandy,
You didn't provide any code many it very difficult to imagine what the error
is...

Yyou can't bind data to a header in the typical databinding sense.
Information is bound row-by-row to the individual items...There's no row
assigned to the header...you can set values of the header progamatically
however...

myGrid.Columns(0).HeaderText =
myDataSet.Tables(0).Rows(0)("Blah").ToString()

or something similar...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Sandy" <Sandy@.discussions.microsoft.com> wrote in message
news:BBD0DEED-455D-473C-8D00-8D969825BCF6@.microsoft.com...
> Hello -
> I don't know if it's possible or not, but I am trying to bind data from a
> Sql Server DB to the header in a datalist. I received the above error
> message.
> First, is it possible to bind data from a DB to the header and if so, what
> could be causing the error message?
> Alternatively, can you only put text in the header of a datalist?
> --
> Sandy
Thanks, Karl!

"Karl Seguin" wrote:

> Sandy,
> You didn't provide any code many it very difficult to imagine what the error
> is...
> Yyou can't bind data to a header in the typical databinding sense.
> Information is bound row-by-row to the individual items...There's no row
> assigned to the header...you can set values of the header progamatically
> however...
> myGrid.Columns(0).HeaderText =
> myDataSet.Tables(0).Rows(0)("Blah").ToString()
> or something similar...
> Karl
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is
> annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
> "Sandy" <Sandy@.discussions.microsoft.com> wrote in message
> news:BBD0DEED-455D-473C-8D00-8D969825BCF6@.microsoft.com...
> > Hello -
> > I don't know if it's possible or not, but I am trying to bind data from a
> > Sql Server DB to the header in a datalist. I received the above error
> > message.
> > First, is it possible to bind data from a DB to the header and if so, what
> > could be causing the error message?
> > Alternatively, can you only put text in the header of a datalist?
> > --
> > Sandy
>

System.NullReferenceException: Object variable or With block varia

Hello -
I don't know if it's possible or not, but I am trying to bind data from a
Sql Server DB to the header in a datalist. I received the above error
message.
First, is it possible to bind data from a DB to the header and if so, what
could be causing the error message?
Alternatively, can you only put text in the header of a datalist?
--
SandySandy,
You didn't provide any code many it very difficult to imagine what the error
is...
Yyou can't bind data to a header in the typical databinding sense.
Information is bound row-by-row to the individual items...There's no row
assigned to the header...you can set values of the header progamatically
however...
myGrid.Columns(0).HeaderText =
myDataSet.Tables(0).Rows(0)("Blah").ToString()
or something similar...
Karl
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Sandy" <Sandy@.discussions.microsoft.com> wrote in message
news:BBD0DEED-455D-473C-8D00-8D969825BCF6@.microsoft.com...
> Hello -
> I don't know if it's possible or not, but I am trying to bind data from a
> Sql Server DB to the header in a datalist. I received the above error
> message.
> First, is it possible to bind data from a DB to the header and if so, what
> could be causing the error message?
> Alternatively, can you only put text in the header of a datalist?
> --
> Sandy

Tuesday, March 13, 2012

system.text.stringBuilder

how can I add a variable in my system.text.stringbuilder

for example notice the example below

Dim myvar as string
myvar = "something"

Dim mystring as system.text.stringBuilder

mystring.append (" myvar ")

the above code does not work. It puts myvar as the literal text and not the actual value of the variable.

Please help with the syntax.You have to take the quotes out:


mystring.Append(myvar)

Thanks! Another question :) How can i retrieve an item from my datalist. For example I can get the Datakey but how can I get a particular item?

Here is the code I use to obtain the datakeys

Dim dlItem As DataListItem
For Each dlItem In detailsgrid.Items
' reference the TextBox
Dim txtItems As TextBox = CType(dlItem.FindControl("item_received"), TextBox)
' Grab the value
item_recieved = txtItems.Text
' Get the order number from DataKeys
order_num = detailsgrid.DataKeys(dlItem.ItemIndex).ToString()