|
Hello All,
Iam trying to create a Windows service. I created a class library which has a few methods which access a database and return data and the service. So in my solution i have 2 projects
1.Class Library called -EventLibrary(all methods here are remotable)
2.InstallerService- which will install this service.
The service is installed and running.
My problem is this.The methods in EventLibrary need to access a database. I tried adding a app config file to the Class library project and added the db connection parameters. But when my client application runs, VS 2005 tries to look for the config item from the client app.config.Since its a 3 tier architecture I dont want to put any config items on the client side.
How do i make the service look for the db config item from the config file in Class Library???
Help and Sample code are much appreciated.
Thanks in advance
RH
|
|
|
|
|
The app.config file need to be where the service is compiled. It gets renamed to the servicename.exe.config. So that is where it is looking for the config settings. So if you move the app.config file out of the class and into the service project it should work just fine.
Ben
|
|
|
|
|
Hi,
I want to display the image in Picture Box in VB 6.0. I have the output in ByteArray. How can I display the image in picturebox?
Thanks in advance,
AR Reddy
|
|
|
|
|
A quick Google for "VB6 convert byte array to bitmap" came up with this[^].
|
|
|
|
|
Example like this:
Create a form within a PictureBox control.
Type the code:
Dim arrayPic() As Byte<br />
Open "testpic.jpg" For Binary As #1<br />
ReDim arrayPic(LOF(1))<br />
Get #1, , arrayPic<br />
Close #1<br />
Picture1.Picture = PictureFromBits(a)
Create a module and type the code:
Public Enum CBoolean<br />
CFalse = 0<br />
CTrue = 1<br />
End Enum<br />
<br />
Public Const S_OK = 0<br />
<br />
Declare Function CreateStreamOnHGlobal Lib "ole32" _<br />
(ByVal hGlobal As Long, _<br />
ByVal fDeleteOnRelease As CBoolean, _<br />
ppstm As Any) As Long<br />
<br />
Declare Function OleLoadPicture Lib "olepro32" _<br />
(pStream As Any, _<br />
ByVal lSize As Long, _<br />
ByVal fRunmode As CBoolean, _<br />
riid As GUID, _<br />
ppvObj As Any) As Long<br />
<br />
Public Type GUID<br />
dwData1 As Long<br />
wData2 As Integer<br />
wData3 As Integer<br />
abData4(7) As Byte<br />
End Type<br />
<br />
Declare Function CLSIDFromString Lib "ole32" (ByVal lpsz As Any, pclsid As GUID) As Long<br />
<br />
Public Const sIID_IPicture = "{7BF80980-BF32-101A-8BBB-00AA00300CAB}"<br />
<br />
Public Const GMEM_MOVEABLE = &H2<br />
Declare Function GlobalAlloc Lib "kernel32" (ByVal uFlags As Long, ByVal dwBytes As Long) As Long<br />
Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long<br />
Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long<br />
<br />
Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)<br />
<br />
<br />
Public Function PictureFromBits(abPic() As Byte) As IPicture<br />
Dim nLow As Long<br />
Dim cbMem As Long<br />
Dim hMem As Long<br />
Dim lpMem As Long<br />
Dim IID_IPicture As GUID<br />
Dim istm As stdole.IUnknown<br />
Dim ipic As IPicture<br />
<br />
On Error GoTo Out<br />
nLow = LBound(abPic)<br />
On Error GoTo 0<br />
cbMem = (UBound(abPic) - nLow) + 1<br />
hMem = GlobalAlloc(GMEM_MOVEABLE, cbMem)<br />
If hMem Then<br />
lpMem = GlobalLock(hMem)<br />
If lpMem Then<br />
MoveMemory ByVal lpMem, abPic(nLow), cbMem<br />
Call GlobalUnlock(hMem)<br />
If (CreateStreamOnHGlobal(hMem, CTrue, istm) = S_OK) Then<br />
If (CLSIDFromString(StrPtr(sIID_IPicture), IID_IPicture) = S_OK) Then<br />
Call OleLoadPicture(ByVal ObjPtr(istm), cbMem, CFalse, IID_IPicture, PictureFromBits)<br />
End If<br />
End If<br />
End If<br />
End If<br />
Out:<br />
End Function
Now you can run your application and see the control of PictureBox shown you a picture from ByteArray.
My English is not very well,so I make some mistakes,maybe!
Don't laugh at me,please!
If you still show no picture from ByteArray,you should send me a email to billypon@21cn.com.
Gook Luck!!!
|
|
|
|
|
Hi Billypon,
Thanks a Lot. Your code is working fine and I am able to display the image. Now I have one more problem is:
I have already image loaded into the memory and I have that memory address pointer. How can I convert that into bytes or bytearray, so that I can use your previous code to display into a picture box.
Thanks in advance.
AR Reddy
|
|
|
|
|
Add this API declare to the Module which I told you.
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
And the write down this function into the Module.
Public Function PictureFromPointer(Pointer As Long, Length As Long) As IPicture<br />
Dim hMem As Long<br />
Dim lpMem As Long<br />
Dim IID_IPicture As GUID<br />
Dim istm As stdole.IUnknown<br />
Dim ipic As IPicture<br />
<br />
On Error GoTo Out<br />
If Pointer > 0 And Length > 0 Then<br />
hMem = GlobalAlloc(GMEM_MOVEABLE, Length)<br />
If hMem Then<br />
lpMem = GlobalLock(hMem)<br />
If lpMem Then<br />
CopyMemory ByVal lpMem, Pointer, Length<br />
Call GlobalUnlock(hMem)<br />
If (CreateStreamOnHGlobal(hMem, CTrue, istm) = S_OK) Then<br />
If (CLSIDFromString(StrPtr(sIID_IPicture), IID_IPicture) = S_OK) Then<br />
Call OleLoadPicture(ByVal ObjPtr(istm), Length, CFalse, IID_IPicture, PictureFromPointer)<br />
End If<br />
End If<br />
End If<br />
End If<br />
End If<br />
Out:<br />
End Function
Now you can use the function like this:
PictureFromPointer(YourPointer,LengthOfPointer)
I was test nothing about this function,so I can't promise it will work fine..
Luckly!!!
-- modified at 22:31 Friday 1st June, 2007
|
|
|
|
|
I am using a DataGrid to retrieve and update data within an Access database. The VB books do a good job in telling me how to use the Insert, Update, and Delete commands for an existing table. However, I would also like to delete an entire table within the Access database and I would like to add a new table according to a DataTable that was created within the VB program. Any suggestions?
Rich Feldman
|
|
|
|
|
During an Update call on the DataAdapter?? This cannot be done. You'd have to supply code to examine each record in the DataSet/DataTable you're Updating and commit the changes to the database yourself, supplying the extra code to create or delete new tables during the process.
Access does respond to the usual SQL commands CREATE TABLE[^]and DROP TABLE[^]. You'd also have to include the field definitions in the CREATE TABLE statement. Executing the SQL command would just involve creating and properly setting up both an OleDbConnection and OleDbCommand object, opening the connection, calling ExecuteNonQuery on the command object, then closing the connection.
|
|
|
|
|
hi all
i have to validate a textbox according to datetime of MM/DD/YYYY
i an new to here(windwos application)please help me how to do
bye byes
prashanth,
s/w Engineer,
Syfnosys.
|
|
|
|
|
Try checking out DateTime.ParseExact[^] method. It will throw an exception if the string doesn't match the format specifier exactly. IF it does return a good date, all you have to do after that is make sure it's within a valid range for your requirements.
|
|
|
|
|
I am developing a VB.NET text based adventure and I need help with coding a log in button.
Basically I have a table called tblUserAccounts
This table as 3 fields...
accountID
username
Password
The log in screen form has a combo box for username and a text box for password with a button just to the right that says Log in.
What I want to happen is that when the person clicks log in after they enter there information into the combo box and text box, that (insert code here) will basically take their username and password(that they entered) and search for it in the database and if it exists in the database allow them to log in.
OR
Alternatively I could make array variables that are = to the table columns(from the database) username and password, then I can perform my own checks in the VB.Net code itself on the button click.
for example I tried doing this...
Dim arrUsername() As Array = GameprojectDatabase.tblUserAccounts.UserColumn
but I get the message that it can not be converted to a 1-dimensional array
If anyone can explain to me how I can do this please let me know.
|
|
|
|
|
This would be easy enough with an SQL query to your Access database:
SELECT COUNT(Username) FROM Users WHERE Username=?Username And Password=?Password
This is, of course, ignoring all security concerns and assumes that all the passwords are stored unencrypted.
All you would have to do is create an OleDbConnection to the database, an OleDbCommand object to execute the query, a couple of OleDbParameter objects, added to the Parameters collection of the OleDbCommand object, with the username and password values filled in, and then call the ExecuteScalar method of the command object. The number returned by that call will tell you how many username/password records matched the inputs. It SHOULD be 1 or 0. If 0, then the login failed. If 1, it worked. If MORE than 1, you've got a consistancy problem with your data as there are more than 1 record in the table with the same username and password.
|
|
|
|
|
Thank you ...Now if I only knew how to do that lol.
I read stuff like this elsewhere but have not found anywhere that explains it clearly. Looking through help files is like trying to find a needle in a haystack, and not only that the needle your looking for has hundreds of twins that confuse the heck out of you.
|
|
|
|
|
I'm sure you've seen something like this:
Public Function AttemptLogin(ByVal Username As String, ByVal Password As String) As Boolean
Dim queryString As String = "SELECT COUNT(Username) FROM User WHERE Username=?Username AND Password=?Password"
Dim result As Integer = 0
Using connection As New OleDbConnection(connectionString)
Dim command As New OleDbCommand(queryString, connection)
command.Parameters.Add(New OleDbParameters("?Username", OleDbType.VarChar, 15)).Value = "someusername"
command.Parameters.Add(New OleDbParameters("?Password", OleDbType.VarChar, 15)).Value = "somepassword"
connection.Open()
result = command.ExecuteScalar()
connection.Close()
Return (result=1)
End Using
End Function
|
|
|
|
|
Hello. That must be quite simple. I have a text file and I want to replace spaces with returns. I'm trying that code, but it doesn't work:
Dim i As Integer = 1
While Not myreader.EndOfStream
line = myreader.ReadLine()
line = i & line.Replace(" "c, vbCrLf)
mywriter.WriteLine(line)
i += 1
End While
myreader is a StreamReader and mywriter is a StreamWriter. Line is a String.
Do you see the problem here?
Regards,
Diego F.
|
|
|
|
|
Standard Question #1: What does "it doesn't work" mean?
What happens? Do you get an error message? What does the expected output look like? What does the actual output look like?
Are both streams created on the same file? You can NOT do that. You can not replace a line in a text file. You have to write an entirely new text file with the modified data.
|
|
|
|
|
I'm sorry for the loose explanation.
myreader references the original file and mywriter a new file
The original file contains large lines with some spaces.
I want to insert line breaks to see the file with more ease.
With the code above, the resulting file is just as the original file. No line breaks are inserted.
Regards,
Diego F.
|
|
|
|
|
OK. Are you sure that the whitespace characters in the original file are spaces and not some other non-visibile character, like Tab?
The code, as you have it, should work, but only for single spaces. You'd be better off using a Regular Expression that can replace all kinds of whitespace characters without you knowing what they are ahead of time:
Imports System.Text.RegularExpressions
.
.
.
' Define a RegEx expression that matches strings
' of 1 or more whitespace characters.
Dim re As New Regex("\s+")
Dim i As Integer = 1
While Not myreader.EndOfStream
line = myreader.ReadLine()
line = i & re.Replace(line, vbCrLf)
mywriter.WriteLine(line)
i += 1
End While
|
|
|
|
|
Thank you for your help.
Regards,
Diego F.
|
|
|
|
|
I replaced " "c for Chr(0) and now it works.
Regards,
Diego F.
|
|
|
|
|
This would answer the question in my previous reply. Those spaces are NOT spaces. The space character you specified is ASCII character 32. The character you supplied in this post is ASCII character 0.
|
|
|
|
|
Hey all,
I wrote a simple web form that has a drop down list with various property locations. I need my code to assign a specific email address to a selectedindex value based on the location.
For instance:
If the user selects Detroit as the location, then the recipient of the mailmessage should be detroit@company.com.
Can I do this correctly in an If/Then statement outside of my MailMessage sub? Like :
<br />
Dim Address As System.Net.Mail.MailAddress<br />
If ddlLocation.SelectedIndex = 1 Then<br />
Address = "helpdesk@turnberry.com"<br />
End If<br />
Obviously I need to convert the string somehow, so any help here would be great.
Thanks!!
|
|
|
|
|
You could do it that way, or you could just get the data from the SelectedItem in the ComboBox, or from the SelectedValue property if you're using a bound ComboBox, or looking up in a table you have. This really depends on how you filled the ComboBox and from what kind of source and the format of the email address.
If it were me, and I'm making a couple of large assumptions here, I'd probably have the Location and email address in a table, bind the combobox to it setting the Location column as the DisplayMember and the email address as the ValueMember, then do something like:
Dim emailAddr As String = ComboBox.SelectedValue
Or
Dim emailAddr As String = ComboBox.SelectedValue @ "@someplace.com"
The second way is less flexible though.
|
|
|
|
|
As you mentioned using the value, I realized how complicated I was making this. Thanks for your direction.
I just added a single line of code in my submit click event and added the emails to the ddl as values and everything works great!
<br />
Dim Email As New System.Net.Mail.MailMessage( _<br />
"email@email.com", ddlLocation.SelectedValue)<br />
Thanks again!
|
|
|
|
|