|
-
Jan 8th, 2007, 03:23 AM
#1
Thread Starter
Fanatic Member
binding databse values to an array
hi, i have table named as emp which ha one column as dob and i am retreiving dob from my tables,it has 5 rows.i wan to insert those 5 rows records into an array.
For j = 0 To ds.Tables(0).Rows.Count - 1
arr1 = ds.Tables(0).Rows(j)("date")
Next
i used this but it shows error,soplease help me to acheive my need
-
Jan 8th, 2007, 03:25 AM
#2
Re: binding databse values to an array
VB Code:
For j = 0 To ds.Tables(0).Rows.Count - 1
arr1[COLOR=Red][U](j)[/U][/COLOR] = ds.Tables(0).Rows(j)("date")
Next
-
Jan 8th, 2007, 03:29 AM
#3
Thread Starter
Fanatic Member
Re: binding databse values to an array
hi jmcilhinney thank you very much
-
Jan 8th, 2007, 03:44 AM
#4
Thread Starter
Fanatic Member
Re: binding databse values to an array
hi jmcilhinney
this is my code, i used your code it shows error as
An unhandled exception of type 'System.NullReferenceException' occurred in helper.exe
Additional information: Object reference not set to an instance of an object.
This is my coding:
dim arr1() as string
cmd = New SqlCommand("sp_sundaycheck", con)
da = New SqlDataAdapter(cmd)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@a", "2007-01-08")
cmd.Parameters.Add("@b", "2007-01-31")
da.Fill(ds, "good")
dim d as integer = ds.Tables(0).Rows.Count - 1
i got d values as 5 becos i retreived 5 rows recods
For j = 0 To ds.Tables(0).Rows.Count - 1
arr1(j) = ds.Tables(0).Rows(j)("date").ToString
Next
please help me solve my error
-
Jan 8th, 2007, 03:49 AM
#5
Hyperactive Member
Re: binding databse values to an array
 Originally Posted by karthikeyan
dim arr1() as string
cmd = New SqlCommand("sp_sundaycheck", con)
da = New SqlDataAdapter(cmd)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@a", "2007-01-08")
cmd.Parameters.Add("@b", "2007-01-31")
da.Fill(ds, "good")
dim d as integer = ds.Tables(0).Rows.Count - 1
i got d values as 5 becos i retreived 5 rows recods
For j = 0 To ds.Tables(0).Rows.Count - 1
arr1(j) = ds.Tables(0).Rows(j)("date").ToString
Next
Hmm....
You have not Dimmed ds as New Dataset and you have not added cmd.ExecuteNonQuery.
Rate Me! Rate Me! Rate Me!
Time to fly.
Copyright GraysonSoft Inc. 2007
-
Jan 8th, 2007, 03:51 AM
#6
Re: binding databse values to an array
You have to have created the array before you can set its elements. This:simply declares a variable. It does NOT create an array. You have to specify the size of the array in order for it to be created. You can't make an egg carton if you don't know how many eggs it has to hold.
VB Code:
Dim arr1(ds.Tables(0).Rows.Count - 1) As String
Also, can you please enclose your code snippets in VBCODE tags to improve readability?
-
Jan 8th, 2007, 03:54 AM
#7
Re: binding databse values to an array
Please not that you must rearrange your code so that the array is created AFTER the DataTable is populated.
Also, why are you declaring your array as type String? You're database column contains Dates so your array should contain Date objects too.
-
Jan 8th, 2007, 03:55 AM
#8
Thread Starter
Fanatic Member
Re: binding databse values to an array
hi tommygrayson, i declared that ds as dataset. and one more thing need not to give execute non query in my code
if i give dim d as integer=ds.tables(0).rows.count i am getting d values as 5
i am getting error while enteirng to this only
For j = 0 To ds.Tables(0).Rows.Count - 1
arr1(j) = ds.Tables(0).Rows(j)("date").ToString
Next
please help me to solve
-
Jan 8th, 2007, 04:00 AM
#9
Thread Starter
Fanatic Member
Re: binding databse values to an array
hi jmcilhinney thank you very much i got it. nice reply
-
Jan 8th, 2007, 04:00 AM
#10
Hyperactive Member
Re: binding databse values to an array
 Originally Posted by karthikeyan
]
For j = 0 To ds.Tables(0).Rows.Count - 1
arr1(j) = ds.Tables(0).Rows(j)("date").ToString
Next
You should use this instead:
VB Code:
arr1(j) = ds.Tables(0).Rows(j).Item(0)
Tell me if it works.
Rate Me! Rate Me! Rate Me!
Time to fly.
Copyright GraysonSoft Inc. 2007
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|