|
I have a problem. I have stored data in the database of particular locations. These locations have Ids .I want to use a combobox to retrieve the names of the Locatios(Towns-Selects only those in database )but save the id in the persons table. Any way to go round this?
|
|
|
|
|
create relations bxn the tables and normalize your database to make it easy otherwise.
try this code but correct the syntax
select the names from locations where id=(select id from persons)
( the only the ID will be in the combobox)
make the syntax correct.
am still a novice so hope sam1 else helps u too.
phatkin
|
|
|
|
|
I have 2 tables
Town(townId,TownName)
Persons_table(Id,Name,TownId)
I would like to use a combobox to display the TownName but the save the TownId in the Persons_table(use to use by the User)
|
|
|
|
|
make a class clsTowns with 2 variables: iid and sname
make 2 public property's in that class id and name
override tostring in the class:
public overrides tostring
return sname
then in the form get all the records from db put each record in a variable of you'r class
and add the class variable to the combobox
dim t as new clstowns
t.id=db.id
t.town=db.town
cbo.items.add(t)
then when you're user selects a item in the combobox the selecteditem contains you're variable of the type clstowns
dim t as clstowns = cbo.selecteditem
and the id can then be extracted from you clstowns variable
dim id as integer = t.id
then you can write it to the db in the persons table
this is only 1 way to do what you want there are other and perhaps better ways
hope this helps
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistaks.
|
|
|
|
|
Thank you for your replay
One more qn
How about the cbo.valueMember and display properties any way to help
Because there are over 3000 towns
|
|
|
|
|
big country you live in
you could indeed use the displaymember and valuemember property's of the cbo but then you still need to iterate thru you're db records and add them 1 by 1
perhaps the DataSource property could help you better. You can pass any collection to this but I would have to test what it does with a datatable, never tryed it so I don't know
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistaks.
|
|
|
|
|
to display the townname in the combobox
dim dt as datatable=nothing 'ur datatable
dim ds as dataset 'ur dataset, load the query results into this dataset
dt=ds.tables(0)
dim dr as datarow
combobox1.items.clear 'optionally clear the combobox
for each dr in dt.rows
combobox1.items.add(dr("townname").tostring
end for
Actually ur explanations is still not clear to me at all
phatkin
|
|
|
|
|
I think the other two guys are a bit off the mark.
Are you saying that you want to show a ComboBox with all of your Town names, have the user pick one of those towns and save its TownId in the Person's record?
You don't have to add each town individually. All you need to do is load the Town data into a DataTable object, then bind the ComboBox to that table. Then, when the user selects a town, you'll have to ID automatically, that you can put into the persons record:
' Get the town data into a DataTable object. I hope you
' already have the SQL done to do this.
' Bind th e Combo to the Towns DataTable object
ComboBox1.DataSource = townsData
' Tell the ComboBox to display the data in the
' TownName column of your data
ComboBox1.DisplayMember = "TownName"
' Tell the ComboBox to use the value in the
' TownId column as the value to be returned when
' the user selects an item
ComboBox1.ValueMember = "TownId"
Now, when the user selects a town, you can use the value of the TownId
Dim selectedTownId As Integer = ComboBox1.SelectedValue
|
|
|
|
|
Thank yo for the reply.
This works up to displaying the Towns but on saving the TownIds are not saved may be you elaborate more.
But it seems you get exactly what i want to do.
|
|
|
|
|
con.Open()
Dim cam As New SqlClient.SqlCommand("select Img from ImgTable where ID='" & Me.NumericUpDown1.Value & "'", con)
Dim rd As SqlClient.SqlDataReader
rd = cam.ExecuteReader
rd.Read()
Dim len As Long = rd.GetBytes(0, 0, Nothing, 0, 0)
Dim arry(CInt(len)) As Byte
rd.GetBytes(0, 0, arry, 0, CInt(len))
con.Close()
Dim memory As New System.IO.MemoryStream(arry)
Dim bmap As New System.Drawing.Bitmap(memory, True)
Me.PictureBox1.Image = bmap
Hi,
the above is the error code. In that con is connecting control. I want to display the stored image in sql to the Picture Box (pictureBox1). Here i got error in " Dim bmap As New System.Drawing.Bitmap(memory, True) " as "Parameters requiered". I dont know where from the error occour. can any one help me to resolve the problem and show the image on the picturebox?
Senthil S
Software Engineer
|
|
|
|
|
I am not sure of the specifics of the problem but a couple of suggestions
1. You are calling getbytes twice, you should perhaps read these into a variable so you only have to do this once, see below
Dim bytes as byte() = CType(rd("img"), Byte())
You can then use bytes.length when you need it. Should be more efficient that way.
2. You are leaving yourself open to SQL injection attacks with the inline sql command coming directly from a control - I would at least put something like
Dim imageId as integer = Me.NumericUpDown1.Value
and use this value - that would mean that an exception would be thrown if someone tried to inject.
You may find that making the change in point 1 fixes the problem, might be worth a shot.
|
|
|
|
|
SHatchard wrote: 2. You are leaving yourself open to SQL injection attacks with the inline sql command coming directly from a control - I would at least put something like
Dim imageId as integer = Me.NumericUpDown1.Value
and use this value - that would mean that an exception would be thrown if someone tried to inject.
it is true that this way of working can mean sql injunctions are possible however in this case it isn't possible since the numericupdown control only accepts numeric values.
just thought I'd point this out
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistaks.
|
|
|
|
|
|
hi
You know what is your Problem?
Answer: you Post without Googling the Question. please Google first before you Post.
your answer is
All2POP is a gateway for POP3 client accessing various web-based email services e.g Hotmail and Yahoo. All2POP takes care of your web-based email accounts
Thank you
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
|
|
|
|
|
You could have found this out yourself in no time at all by typing that exact phrase into Google.
|
|
|
|
|
Hi Everyone,
Wasn't sure if this was a VB or SQL question and where to post so I am trying here.
I read it is better to use stored procedures and functions on the SQL server to centralise and re-use code, as well as allowing us to restrict rights to EXECUTE rather than full rights.
I wanted to retrieve (and maybe in another function SET), some data so I wrote the following basic function and stored it on the server. My problem is that no matter how I try, I can't seem to find a way to call the function from my VB.NET 2005 application. Please help
ALTER FUNCTION dbo.GetEmployeeFont
(
@EmployeeID int
)
RETURNS TABLE
AS
RETURN
(SELECT FontName, FontSize
FROM tblEmployees
WHERE (EmployeeID = @EmployeeID))
|
|
|
|
|
That would be better as a stored procedure if you are going to call it from VB
|
|
|
|
|
To call a function in T-SQL you would do e.g. :
SELECT * FROM dbo.GetEmployeeFont(2100)
To call a stored prcoedure:
EXECUTE dbo.GetEmployeeFont 2100
So first you need to know whether you are intending to use a function or a stored proc...
|
|
|
|
|
Thanks Duncan.
I need to return some values and use them so I think the function would be best.
Excuse my ignorance but my previous coding was for MSAcess so I"m trying to learn SQL server issues, and move from VBA to VB.NET.
I have put in the SELECT statement you sugessted but the compiler tells me "Select CASE must end with a matching END SELECT", and hovering over FROM in the statement gives me "name not declared" . Obviously I need more code to setup the SQL statement - could you kindly give me an example please.
Many thanks
Mark
|
|
|
|
|
i am working on a particular application
where i am actually writing a code of tree with chech boxes
where each box is acually playing a node
now if we select a checkbox for a particular nodes
all the nodes that come under it must get selected
and when deselect it all the subsequent nodes/nested are deslected.
this is pretty staright forward as far as the logic/programming is concerened ....
Now the case is...
suppose if i have a super node A with subnodes x,y,z
if i only select x and does not select y and z
should the check box A should show selected or not selected
what if it shows selected but is shadowed.
will it go on to solve the problem?
|
|
|
|
|
don't really know what you mean with 'shadowed' so it's possibly the same as what I'm going to say now (if so: sorry).
a checkbox (a standerd one so one in treeview normally too) has 3 'checkstate's: unchecked,checked and indeterminate.
In you're case (where super node A with subnodes x,y,z and x = selected) I would put super node A to indeterminate and adjust you're code to do the checks on the checkstate property and not on the checked property
after checkedstatechanged (or some other event (don't know it by heart)) of super node A
If A.checkstate = unchecked then
uncheck all subnodes
else
check all subnodes
end if
after checkedstatechanged (or some other event (don't know it by heart)) of supnode x
if x.checkstate = unchecked then
uncheck subnodes
see if other subnodes of super node are checked
if x.parent.nodes ... = checked
super node A.checkstate = indeterminate
else
super node A.checkstat = unchecked
end if
end if
hope this helps
it's a bit difficult to read (I know) but read it twice and you'll get the idea
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistaks.
|
|
|
|
|
Hi all,
I have a little bit of a problem that I really need to find a solution for. What I have made is a custom collection class(inherits from collectionbase and all that) which holds around 200000 objects(these are custom objects too).
The problem is when I need to sort this really big list of items, the program just locks up and takes forever to finish the sort(I haven't let it run the full way through yet because It runs the computer low on memory).
I have had a look around on the net for fast array sorting and have found a few good ones but the ones I find seem to only able to sort small arrays and still fall over when you hand them my item list.
Can anyone help me with this.
Thanks
Nathan
|
|
|
|
|
to solve the locking problem: use threads (do some reading on the subject if you've never worked with them before)
dim thr as new threading.thread
...
this will in no means make the sorting better or faster but at least you're programe will still be able to accept user input.
to solve (or at least try too) the memory problem look at you're code and check if you haven't forgotten to dispose of unused object. I was able to tweak one of my program's (that I wrote at the start of my academic carreer(long time ago )) to use 50% less memory just by cleaning everything up.
for the sorting problem I don't imidiatly have anything (sorry)
hope this helps
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistaks.
|
|
|
|
|
I have an application that uses a datagrid and links a dataview to this datagrid.
I have some 284,000 rows in the datagrid and a sort takes 3.5 seconds (which I consider to be a decent response time). I'm not sure what sort of speed you are looking for.
As a DBA I would suggest not sorting the data but rather building an index object and link this to your collection.
You can then sort the index instead of your collection.
You could build an arraylist that links to your collection.
Sort the arraylist(index) instead of the collection et voila...
Let me know if this is helpful or totally goofy...
You always pass failure on the way to success.
|
|
|
|
|
Thank you both for you input.
I had a bit of a play around with the datagrid and it does work well but this part of the program doesn't need to have a UI. I'm working with the index idea right now, seems to be working fine for what I need, still slow compared to the datagrid but no big deal. I have threaded it to so that the program dosn't lock up.
Thanks
|
|
|
|