|
|
Hi, i need to prevent users from pasting into the combo box.
how do i do this?
mo.
|
|
|
|
|
I dont know the best way but the tricky part is
1. put a context menu on your form and dont add any thing in it.
2. assign this context menu to combo box in combobox properties name context menu
3. in key press event of combobox write
e.handled =true
for 100% read only you can make dropdown style of combobox to dropdownList
|
|
|
|
|
I found an easy way to do this is to make the combobox ownerdrawn, and make the combobox a dropdownlist. I personally made a usercontrol with a combobox on it, and handled the 'DrawItem' event of the combobox with:
<br />
Private Sub ComboBox1_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles Main.DrawItem<br />
Dim cmb As ComboBox = CType(sender, ComboBox)<br />
If e.Index = -1 Then<br />
Return<br />
End If<br />
If sender Is Nothing Then<br />
Return<br />
End If<br />
Dim Color1 As Color = Color.Black<br />
Dim g As Graphics = e.Graphics<br />
'string brushName = (string)cmb.Items[die.Index];<br />
'SolidBrush selectedBrush = (SolidBrush)brushMap[brushName];<br />
Dim selectedbrush As New SolidBrush(Color1)<br />
selectedbrush.Color = Color1<br />
' If the item is selected, this draws the correct background color<br />
e.DrawBackground()<br />
e.DrawFocusRectangle()<br />
Dim rectPreviewBox As Rectangle = e.Bounds<br />
<br />
Dim item As String = CType(cmb.Items.Item(e.Index), String)<br />
' Draw the name of the color selected<br />
Dim font As New Font("Times New Roman", 12, FontStyle.Regular, GraphicsUnit.Pixel)<br />
g.DrawString(item, font, New SolidBrush(e.ForeColor), e.Bounds.X, e.Bounds.Y + 1)<br />
End Sub<br />
<br />
|
|
|
|
|
Hi everyone - im trying to develop a solution whereby an existing excel spreadsheet gets submitted to an online SQL server database.
The excel sheet is flat one dimensional and without formula.
I have currently got all the information from the sheet into an array...my question is how to get the information into sql server from VBA. Can I use something like the following..
Dim DB As DAO.Database
Set DB = DBEngine.OpenDatabase("server=localhost;database=blah")
or do i need to implement webservices...next question is can a webservice handle an array as a parameter or do i need to rethink my logic at the spreadsheet level.
I have pulled code snippets from google, and there seems to have been so many different providers database engines / references needed that im completely confused. What should i be using with Excel 2002 - what is the most stable db engine.
|
|
|
|
|
'you may need to add refrences for this to work look ADO library
'DataBase Connection parameters
Public stConn As String 'Connection String
Public Cnt As New ADODB.Connection 'Connection Object
public StConn as String
stConn = "Provider=sqloledb;" & _
"Data Source=ServerName;" & _
"Initial Catalog=Database;" & _
"User Id=sa;" & _
"Password=yourpassword;"
Cnt.OPEN strconn
Qry_str = "your Query Insert,Update,Delete;"
Cnt.Execute Qry_str
Mandar Patankar
Microsoft Certified professional
|
|
|
|
|
Thanks for the reply Mandar
Dim strConnection, Password, User, InitialC, Source
Source = "PAULANT" 'Your server name
User = "sa" 'The SQL user you want to use (probably 'sa')
Password = "blah" 'The password for the previously defined User
InitialC = "blah" 'The database you wish to maintain
strConnection = "Provider=SQLOLEDB;Persist Security Info=False;Password=" & Password & ";User ID=" & User & ";Initial Catalog=" & InitialC & ";Data Source=" & Source
Set objCommand = New ADODB.Command
objCommand.ActiveConnection = strConnection
''' Load the SQL string into the Command object.
objCommand.CommandText = "INSERT INTO tbl_register (fld_name) Values ('test')"
''' Execute the SQL statement.
objCommand.Execute
- This works - but using an IP Address doesn't work....I want to perform this command with a remote SQL Server
|
|
|
|
|
Add another parameter in your connect string: "SERVER=999.999.999.999;"
Like so -
Dim strConnection, Password, User, InitialC, Source, Server
Server = "999.999.999.999" 'Set your own IP here
Source = "PAULANT" 'Your server name
User = "sa" 'The SQL user you want to use (probably 'sa')
Password = "blah" 'The password for the previously defined User
InitialC = "blah" 'The database you wish to maintain
strConnection = "Provider=SQLOLEDB;Server=" & Server & ";Persist Security Info=False;Password=" & Password & ";User ID=" & User & ";Initial Catalog=" & InitialC & ";Data Source=" & Source
Goodluck!
Cprompt
|
|
|
|
|
I´ve got a report to show in VB.NET which i created using the embedded crystal reports designer that comes with visual studio. In that report i´ve got two tables in a dataset linked by a common field. The report has about 1000 rows and it takes too much time too load. And in top of all, cpu usage goes up to 99%... I read in google that in the crystal reports software (the full version) there is an option called "save data with report", that if it´s disabled can speed up the report load, but i can´t find it anywhere in visual studio.
Sorry about my english, and thanks for reading, i really need an answer!
|
|
|
|
|
On a form i created a structure and i generated a variable ,set its properties, then added to combobox items, But when i run the form , combobox have items like "BackApp.Form1+ComboItemX" what s problem?
Public Structure ComboItemX<br />
Public ID As Integer<br />
Public Value As String<br />
End Structure<br />
<br />
Protected Sub ReadTemplates()<br />
Dim itemX As ComboItemX<br />
cmbTemplates.Items.Clear()<br />
cmbTemplates.DisplayMember = "Value"<br />
cmbTemplates.ValueMember = "ID"<br />
itemX.ID = 0<br />
itemX.Value = "NEW TEMPLATE"<br />
cmbTemplates.Items.Add(itemX)<br />
Try<br />
cn.Open()<br />
cmd.CommandText = "SELECT * FROM TEMPLATES "<br />
dr = cmd.ExecuteReader<br />
Do While dr.Read<br />
Dim item As ComboItemX<br />
item.ID = dr.Item("TEMP_ID")<br />
item.Value = dr.Item("TEMP_NAME")<br />
cmbTemplates.Items.Add(item)<br />
Loop<br />
Catch ex As Exception<br />
ShowErrorMessage(ex)<br />
Finally<br />
dr.Close()<br />
cn.Close()<br />
End Try<br />
End Sub
|
|
|
|
|
Hi there,
I have a code which check for the url and return me the output in excel file the problem is i got a identifier in my data base which is '000002435' but while transfer into excel i get only '435' any suggestion here is the code snippet
With Excel
.SheetsInNewWorkbook = 1
.Workbooks.Add()
.Worksheets(1).Select()
For intColumn = 0 To ds.Tables(0).Columns.Count - 1
.Cells(1, intColumn + 1).Value = ds.Tables(0).Columns(intColumn).ColumnName.ToString
Next
'For displaying the column value row-by-row in the the excel file.
Dim o As Object
For intRow = 0 To ds.Tables(0).Rows.Count - 1
For intColumnValue = 0 To ds.Tables(0).Columns.Count - 1
.Cells(intRow + 2, intColumnValue + 1).Value = ds.Tables(0).Rows(intRow).ItemArray(intColumnValue).ToString
Next
Next
.ActiveWorkbook().SaveAs("C:\excel\excelsheet_output.xls")
.ActiveWorkbook.Close()
End With
regards
cyus
|
|
|
|
|
Is the Excel cell value showing as 435 or 2345? In any case it is probably a cell formatting issue where the Excel cell is either 1. (for showing 435) only wide enough for three digits or 2. (for showing 2345) trimming all leading zeros from the value.
In case 1. set the cell column width to accomodate all the data. For case 2. you'll need to preserve the leading zeros and insert that as a string value (not numeric) into the cell.
...Steve
|
|
|
|
|
A VC dll provide some binary data , I receive it with VB 6.0.
In VC++ 6.0 , the interface is:
bool __stdcall GetData(unsigned char **pData);
After get the data, I should release the memeory.
How to receice the data?
Thanks!
|
|
|
|
|
I have the following stored proc:
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
ALTER PROCEDURE dbo.stp_SelTransOverrides
-- SELECT ALL EIS TRANSACTION PROCESSING OVERRIDE RECORDS
/*******************************************************************************
*** Name: dbo.stp_SelTransOverrides
*** Creation Date: 08/17/2005
*** Author: Mathieu Cupryk
*** Modified:
***
*** Input: none
*** Output: ALL Transaction Override Records
*** Order: Transaction_Eff_Date
*** Database: CCFinSol
*** Purpose: Select all TransactionOverride Records
***
*** Copyright: @2005 - Corporate Customer, Zurich N.A., all rights reserved
********************************************************************************/
AS
BEGIN
SELECT dbo.AcctNames.Acct_Name AS [Account Name], dbo.TransOverride.Policy_Nbr AS [Policy Number],
dbo.TransOverride.Trans_CodeOrig AS [Original Transaction Code], dbo.TransOverride.Trans_Eff_Date AS [Trans. Eff. Date],
dbo.TransOverride.Override_Code AS [Override Action], dbo.TransOverride.NR_CodeOvr AS [Override New/Renewal],
dbo.TransOverride.Trans_CodeOvr AS [Override Transaction Code], dbo.TransOverride.CreatedUID AS UserId, dbo.TransOverride.ModifiedDate AS Date
FROM dbo.AcctIDPolicyX INNER JOIN dbo.AcctNames ON dbo.AcctIDPolicyX.Acct_Id = dbo.AcctNames.Acct_Id INNER JOIN dbo.TransOverride ON dbo.AcctIDPolicyX.Policy_nbr = dbo.TransOverride.Policy_Nbr
ORDER BY dbo.TransOverride.Trans_Eff_Date
RETURN 0
END
GO
I must populate a grid.
Can someone start me off.
Case clsUtilityTableDatAdap.UtilityTableID.TransOverride
_UtilityTableName = "Transaction Override"
_UtilityTableDap = clsUtilityTableDatAdap.GetTransOverrideDap(_cnnFinSol)
_UtilityTableDap.Fill(_UtilityTableDset)
_UtilityTableDset.Tables(0).PrimaryKey = _
New DataColumn() {_UtilityTableDset.Tables(0).Columns("Policy_Nbr"), _UtilityTableDset.Tables(0).Columns("Trans_CodeOrig"), _UtilityTableDset.Tables(0).Columns("Trans_Eff_Date")}
The I am not the table is structured
CREATE TABLE [TransOverride] (
[Policy_Nbr] [varchar] (7) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Trans_CodeOrig] [varchar] (6) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Trans_Eff_Date] [datetime] NOT NULL ,
[Override_Code] [varchar] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[NR_CodeOvr] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Trans_CodeOvr] [varchar] (6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[CreatedDate] [datetime] NOT NULL CONSTRAINT [DF__TransOver__Creat__70A8B9AE] DEFAULT (getdate()),
[CreatedUID] [nvarchar] (48) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF__TransOver__Modif__719CDDE7] DEFAULT (getdate()),
[ModifiedUID] [nvarchar] (48) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Plan_Year] [int] NOT NULL CONSTRAINT [DF__TransOver__Plan___56757D0D] DEFAULT (2004),
CONSTRAINT [cnTransOverride_PK] PRIMARY KEY CLUSTERED
(
[Policy_Nbr],
[Trans_CodeOrig],
[Trans_Eff_Date]
) ON [PRIMARY] ,
CONSTRAINT [cnTransOverride_NR_CodeOvr_CK] CHECK ([NR_CodeOvr] = '' or ([NR_CodeOvr] = 'R' or [NR_CodeOvr] = 'N')),
CONSTRAINT [cnTransOverride_Override_Code_CK] CHECK ([Override_Code] = '' or ([Override_Code] = 'OT' or ([Override_Code] = 'AU' or ([Override_Code] = 'MS' or ([Override_Code] = 'EN' or ([Override_Code] = 'AO' or [Override_Code] = 'AC'))))))
) ON [PRIMARY]
GO
I need to get started building the dataset and the sqladapter and to be able to populate the grid.
Any help or Suggestions would wonderful.
Thank You
|
|
|
|
|
Why does your SP return 0 ? If you call the stored procedure, you'll get back a dataset, you can then grab the one table in that data set and make it the datasource on a DataGrid. That's all you need to do to get a basic display of your data.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
what should the SP return instead of "0"?
|
|
|
|
|
Nothing, why does it matter ? It returns the tables, the scalar does not matter most of the time.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Please, talk to me about:
How do you get list of machines in LAN by VB.NET?
Thanks very muchs.
Phuoc Tuyen
|
|
|
|
|
|
Depends on what you want to achieve, but I have used this VB.NET code to query Active Directory. You will need to modify it for your purposes. Lookup the help on the objects shown here for examples of what they can provide.
Imports System.DirectoryServices
Private Sub ScanMachines()
'
' Get the list of machine names in the current domain
' as specified by txtMachineSpec.
'
Dim ds As New DirectorySearcher
ds.SearchRoot = New DirectoryEntry
Dim wildcards() As String = Split(txtMachineSpec.Text.ToUpper, ",")
ds.Filter = GetFilterString(wildcards)
ds.PropertyNamesOnly = True
ds.PropertiesToLoad.Add("name")
ds.Sort = New SortOption("name", SortDirection.Ascending)
ds.PageSize = 9999
Dim src As SearchResultCollection
Try
'
' Enumerate the machines in AD.
'
src = ds.FindAll()
Try
For Each sr As SearchResult In src
'
' Get the machine name, stripping off the "CN=" portion
' as we go.
'
Dim de As DirectoryEntry = sr.GetDirectoryEntry()
Dim machineName As String = Replace(de.Name, "CN=", "", 1, 1)
'
' Do your stuff here ...
'
Next
Catch ex As Exception
MessageBox.Show("1: " & ex.Message)
End Try
Catch ex As InvalidOperationException
MessageBox.Show("2: " & ex.Message)
Catch ex As NotSupportedException
MessageBox.Show("3: " & ex.Message)
Catch ex As Exception
MessageBox.Show("4: " & ex.Message)
Finally
If Not src Is Nothing Then
src.Dispose()
End If
If Not ds Is Nothing Then
ds.Dispose()
End If
End Try
End Sub
...Steve
|
|
|
|
|
|
Hi I'm trying to code a calendar control so that I can use this control to show dates (emphasis on several dates) highlighted in the month view of the control.
I am trying an Active X control, MSCAL.Calendar.7, but it may not support what I need to do.
I want to highlight several dates on a Month view of the calendar control, preferably in a color like red or something other than Grey/depressed.
What properties can do this for me and where should I look for examples?
Thanks,
REMOTE USER
|
|
|
|
|
Sorry, this is in Access, using VBA to code it up.
|
|
|
|
|
Hi all.
It might be the late hour but I can't figure out why this little piece of code won't work when I apply it in the real world:
' selectTest should eval to true...<br />
Sub doTest()<br />
selectTest 543<br />
End Sub<br />
<br />
Function selectTest(intAntal%)<br />
Select Case (intAntal)<br />
Case ((30 / 20) * 100), Is >= 100<br />
selectTest= True<br />
Exit Function<br />
Case Else<br />
selectTest= False<br />
End Select<br />
End Function
While this work, the equaling real code won't:
With objStation.Parkeringer(intP).Taellinger(intT)<br />
Select Case (.intAntalPladser)<br />
Case 0<br />
SkalMed = True<br />
If .intAntalParkeret = 0 Then<br />
MsgBox "På " & objStation.strNavn & " er der en tælling med" & _<br />
" 0 P-pladser og 0 parkeret." & Chr(10) & _<br />
"Stationen kommer med i rapporten.", vbInformation, "Advarsel"<br />
End If<br />
Exit Function<br />
Case ((.intAntalParkeret / .intAntalPladser) * 100), Is >= intBelaegningsprocent<br />
SkalMed = True<br />
Exit Function<br />
Case 1345, Is > 90 ' the code should at least stop here... but doesn't<br />
Stop<br />
Case Else<br />
SkalMed = False<br />
End Select<br />
End With
The above select case (almost) always returns false. It seems like it works sometimes. Like when intBelaegningsprocent is set to 5 but not 80 or 90.
Any ideas on why this happens?!?
Regards Jon.
Moving to C# .NET - the grass is always greener..
|
|
|
|
|
Jon,
There are many implicit data type conversions in this code (i.e. double to integer, float etc...). Maybe the erratic behaviour of the Select is caused by this?
My advice is to strictly type each variable and function to ensure that you are comparing similar data types rather than letting the compiler make its best guess at it.
e.g.
<br />
Option Strict On<br />
<br />
Function selectTest(ByVal intAntal As Integer) As Boolean<br />
<br />
Select Case (intAntal)<br />
<br />
Case CInt((30 / 20) * 100), Is >= 100<br />
selectTest = True<br />
'Exit Function<br />
<br />
Case Else<br />
selectTest = False<br />
<br />
End Select<br />
<br />
End Function<br />
Maybe the code in your second example is not stopping at Case 1345, Is > 90 is perhaps the case variable .intAntalPladser is neither 1345 nor > 90; or an exception is being thrown here or in preceeding Case statements. To investigate this, wrap the code in a a Try..Catch block to trap and display any errors.
...Steve
|
|
|
|
|