|
I have a field of Image path on database and I need to display the image of student in crystal report. I am using VS2005 with crystal report version 9. I have added the unbound column named "Image" of type system.byte in Data Set and at the load event, I have write the following code.
Dim da As New DataSet1TableAdapters.AdmissionFormTableAdapter
Dim dt As New DataSet1.AdmissionFormDataTable
da.FillByStudentID(dt, _studentID)
Dim dtCopy As New DataTable
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Code Start to Set Image
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim blankFile As String = "C:\Program Files\blank.JPG"
If dt.Rows(0).Item("ImagePath").ToString <> "" Then
Dim s As String = dt.Rows(0).Item("ImagePath").ToString
If FileIO.FileSystem.FileExists(s) Then
Dim fs As FileStream = New FileStream(s, FileMode.Open, FileAccess.Read)
Dim image(fs.Length) As Byte
fs.Read(image, 0, Convert.ToInt32(fs.Length))
dt.Rows(0).Item("Image") = image
fs.Close()
Else
Dim fs As FileStream = New FileStream(blankFile, FileMode.Open, FileAccess.Read)
Dim image(fs.Length) As Byte
fs.Read(image, 0, Convert.ToInt32(fs.Length))
dt.Rows(0).Item("Image") = image
fs.Close()
End If
Else
Dim fs As FileStream = New FileStream(blankFile, FileMode.Open, FileAccess.Read)
Dim image(fs.Length) As Byte
fs.Read(image, 0, Convert.ToInt32(fs.Length))
dt.Rows(0).Item("Image") = image
fs.Close()
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Code End to Set Image
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
dtCopy = dt.Copy
Me.rptAdmissionForm1.SetDataSource(dtCopy)
Me.rptAdmissionForm1.SetParameterValue("ID", _studentID)
When I run the code, error comes that "unable to cast type of system.byte to system.IConvertible",
although the datatype of column "Image" is system.byte, and when I debug the code, it shows the datatype of dt.Rows(0).Item("Image") = System.DBNull, Please help me out..!
|
|
|
|
|
For x = 0 To y
RandomNumber = RandomClass.Next(i)
Next x
is the Code I'm using what I'm wondering is there a way to check and make sure the same random number doesn't get picked twice?
|
|
|
|
|
The principle is that you would need to store each number you generate, and check each new random number against that store. Could get very expensive if you are generating a large number of random numbers.
|
|
|
|
|
I understand to use it as an array and check it against each other however I don't know the code you would use to check
RandomNumber(r) where r were to equal 9 against 0-8 if you could help me with that I'd greatly appreciate it.
|
|
|
|
|
GregoryWB wrote: is there a way to check and make sure the same random number doesn't get picked twice?
That is not the purpose of a random number generator: it should generate numbers that are independent of previous numbers, hence doubles are perfectly normal.
If you need all different numbers, randomly picked from a limited set, then that is what you should do: construct a set, pick one element from it randomly and remove it, then repeat until you have enough (or the set got empty).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
well I'm trying to create a Raffle program with Name(x) and it has more then 1 winner, I'm fairly new to programming so not sure how to remove 1 Element each time it is selected, any pointing to document that would explain this or help would be great.
|
|
|
|
|
GregoryWB wrote: not sure how to remove 1 Element
Well, use a real collection such as a List<int> and fill it with all N relevant numbers.
Run your random generator for the range [0, N-1] and use that number as an index into the List, copy that number AND remove it from the list (which now has one fewer element, so adjust your random.Next call next time you call it).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
That the OP was building a raffle number program would have been fairly pertinent information, don't you think?
In that case I would have recommended the same approach you did!!
|
|
|
|
|
Private Function rnd_between_limits() As Integer
Return (Int(( Initial_limit+final limit-1 ) * Rnd(Now.Millisecond + Now.Minute + Now.Second)) + Initial_limit )
End Function
use this if ya want to generate a rnd number between certain limits
TheMrProgrammer
|
|
|
|
|
Hi all,
I am trying to write a simple application that will read data from a SQL database and allow the user to make changes and then update the database.
I am using VB 2008 Express on a XP machine and SQL Server 2005.
The program will be run on different servers with static ip addresses.
The program will consist of two user forms:
1. Login form (User name and password is stored in a table in the database)
2. Main Form (A Customer Masterfile table in the database)
I have done a bit of coding in VBA, but would like to do this in VB 2008 so that I can generate a standalone app that can be run without excel.
My idea is to do it bit by bit and learn as I go along, but I want to start the right way so that I do not have to redo everything at a later stage.
My logic is as follow:
Create Login form with Username, Password, Ok button, Cancel Button, Server Info.
(the username and password will be verified against the values in the database)
The IP, Databasename, Sql Login and Sql password must be entered and remembered next time the program is run. In VBA I would store this info in a Excel sheet, but were can I store this when using VB2008?
If the login is ok it will load the Main form otherwise you need to retry the password.
The Main form will get information from a customer masterfile that will be loaded in text boxes that can be edited and once complete it can be uploaded to the database.
For a start I would like to do the userform and server connection.
Any help would be appreciated.
Thanks.
|
|
|
|
|
Seems like reasonable logic...
For simplicity, instead of prompting the user for the IP, Database Name, SQL Login etc, why not store these either in the app.config file, or in a global constant within your system.
If at a later time you want the user to enter these during setup, or whatever, you can update your system to handle that...
Hint for login form - use a couple of text boxes for username and password. Open a connection to the database (see www.connectionstrings.com for help) and get a datareader for the record containing the specified username. If the datareader is empty, the user does not exist. If the datareader is not empty, compare the passwords and let in/deny access depending on how it goes.
|
|
|
|
|
Thank you for the reply Damian.
I found a article on Code Project on creating an app.config file and this seems to be the easiest way for a start. Like you said I could always expand on that at a later stage. ( would I then edit the app.config file through code, or is this done in another way?)
I will attempt to get login form going following your advice.
Thanks again!
|
|
|
|
|
There are several different ways of updating an app.config file - certainly through code is one way.
Good luck with the login form!
|
|
|
|
|
Follow Damiens advice and think about the SQL login types.
Active Directories - this uses the AD user groups and a connection is created using the users credentails
App Connection - this is where the application has a standard SQL logon and uses that to get the data (you need this to get the logon information anyway).
We use the latter but we use internal authorisation to manage the internals of the apps.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hello
i am developing an application where i generate my report in excel
and have to save in some folder in c drive i wrote my code like
Dim xl As New Excel.Application
xl = CreateObject("Excel.Application")
Workbooks.Add()
xl.Visible = True
xl.Columns("A").columnwidth = 5
xl.Columns("C").columnwidth = 25
xl.Columns("B").columnwidth = 25
With xl.Range("A" & ii, "C" & ii)
.Interior.ColorIndex = 5
End With
'please suggest also how to change forecolor of cell from "A" to "C"'
i get my data from data base and load it in excel and it is working but now i want to save this file in some folder for that i wrote code like
If Not IO.Directory.Exists("C:\Backup") Then
IO.Directory.CreateDirectory("C:\Backup")
End If
xl.SaveWorkspace(" C:\Backup ")
but this code is not working
so,please suggest what shall i do to save it in this directory...
|
|
|
|
|
nazimghori wrote: but this code is not working
So what errors are you getting? Any exceptions? Do you have rights to save there? What OS are you running on, and under what type of user account?
|
|
|
|
|
nazimghori wrote: please suggest also how to change forecolor of cell from "A" to "C"'
Try using:
range.interior.color =
|
|
|
|
|
Well, the save fails because you haven't provided a file name. You gave it the anme of a folder, but no filename...
|
|
|
|
|
Hi all,
Can somebody help me/point me on how to register an exe as a service. I googled for it but it lead to confusion more than any help.
My exe would require a command line argument to start. So I can put it in a batch file and would like to register the batch file as a service.
Thanks
--Raghu
|
|
|
|
|
I seriously do not recommend doing this, but you can use SrvAny[^] to run an .EXE as a service.
|
|
|
|
|
Ditto. What is so hard about using InstallUtil? If you need an installer, use this KBA: http://support.microsoft.com/kb/816169
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Hi
Let me explain.
I have an application built on VC++ 2005 (myApp.exe). I want to install it as a windows service. My application requires a an argument to start. How I do that.
As I am new to this, I created a service with notepad.exe as the executable, but when I try to start it, this is what I got
Error 1053: The service did not respond to the start or control request in a timely fashion
I have the .net 2.0 framework installed.
Only straight answers please. The one like ..
>>Ditto. What is so hard about using InstallUtil? If you need an installer, use this KBA:
by Jon_Boy is of no help, unless you are half bald ( or may be completely bald, you need to get bald to get the solution from Jon_Boy)
Thanks
--Raghu
modified on Wednesday, May 27, 2009 6:43 AM
|
|
|
|
|
Raghuveer D wrote: unless you are half bald ( or may be completely bald, you need to get bald to get the solution from Jon_Boy)
And that means what?? Bald people don't know what they're doing??
You're getting the error message because the ServiceManager is expecting a response to a Start command that it is not getting back. Why? Because your code is not written as a "pure service".
Rewrite your application as a service and you won't have any of these problems. That is, if your not half-bald and really know how to write a proper service app...
|
|
|
|
|
Sorry, I showed my frustration there. Anyways, people who know lot of things, seen lot of things get bald( not necessarily though). I always had that belief that bald guys have more information in their brains. Correct me if I am wrong.
|
|
|
|
|