|
|
Excellent help, Mike! That's exactly what I needed and having just tried it find it works great. Thanks!
Mitchell
|
|
|
|
|
VB.Net
ADO.Net
How do I populate textbox(s) from column(s) from the same data row from a Combobox?
These items are of course generically named for demonstation purposes only.
I have…
DataSet1
Table1
Column1
Column11
Textbox1 which is bound to DataSet1, Table1, Column1
Textbox2 which is bound to DataSet1, Table1, Column11
DataSet2
Table2
Column2
Column22
All columns in Table2 are Doubles.
ComboBox3
The form that is displayed is populated from DataSet1.
ComboBox3 source and value member is set to DataSet2, Table2, Column2.
I only want to display one column in the ComboBox.
To populate Textbox1 on SelectedValueChanged of ComboBox3 I have…
Me.Textbox1.Text = Val (Me.ComboBox3.Text)
This works fine.
But I want to populate Textbox2 from Column22, with the corresponding value that is in the same row as the value selected to populate Textbox1 at the same time.
DataSet2
Table2
Column2
1
2
3
4
5
Column22
11
22
33
44
55
So if Textbox1 was populated with “4”, I want Textbox2 to be populated with “44” at the same time, (they are on the same DataRow).
Eventually I would like to populate other textboxes as well, or just simply expand on this. In Access this was easy to do, but I am moving to and using VB.Net and ADO.Net.
How do I do this?
Thanks
WindSailor
|
|
|
|
|
I'm a little lost between the DataSet1 and DataSet2, but it seems that the combobox is bound to DataSet2 and the info from that DataSet is what you want in the other textboxes, so:
It is very easy to do this using BindingManagerBase. I had to look through five books on ADO.NET before finding one that explained how to use it. I'm not sure why the other books ignore it because it makes things a lot simpler. (Murach is the the publisher)
Bind your controls
In your code:
1) Dim bmbName As BindingManagerBase 'before the Form Designer generated code
2) bmbName = Me.BindingContext(DsName1, "TableName") 'after the dataset's been filled
3) Private Sub cboName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboName.SelectedIndexChanged
bmbName.Position = cboName.SelectedIndex
End Sub
Now the other controls will change as you change the combobox.
|
|
|
|
|
Thanks!
DataSet2 was a lookup table for DataSet1 or for the form I was working on, I actually have 17 different lookup tables integrated into this form. Busy, yes.
I included your suggestions and made changes on some of the items...
I needed to change the DataBindings to retrieve the value of the LookUp Column and then save that value to the original Table and Column that the form was built on.
In your code:
1) Dim bmbName As BindingManagerBase 'before the Form Designer generated code
2) bmbName = Me.BindingContext(DsName1, "TableName") 'after the dataset's been filled
2a) NOTE: I actually changed it to:
bmbName = Me.BindingContext(YourLookUpDataSet,"YourLookUpTableName")
'after the DataSet's been filled
3) Private Sub cboName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboName.SelectedIndexChanged
Dim ThisVariable1 As Double
Me.TextBox2.DataBindings.Clear()'Databinding was originally done on the _
'property settings of TextBox2 so I could scroll through records.
bmbName.Position = cboName.SelectedIndex
Me.TextBox2.DataBindings.Add(New Binding _
("Text",YourLookUpDataSet, "YourLookUpTableName.YourLookUpColumnName"))
ThisVariable1 = Me.TextBox2.Text
Me.TextBox2.DataBindings.Clear()
Me.TextBox2.DataBindings.Add(New Binding _
("Text", YourOriginalDataSet, "OriginalTable.OriginalColumn"))
'reset to your original DataBinding.
Me.TextBox2.Text = ThisVariable1
ThisVariable1 = 1 'Setting default value for that column
Me.BindingContext(YourDataSetName, "YourTable").EndCurrentEdit()
YourDataAdapter.Update(YourDataSetName, "YourTable")
End Sub
This does work for me, I hope this is what you were talking about... if not please expand on it.
Thanks again,
Windsailor
|
|
|
|
|
I'm glad to hear it worked for you. My example was just to get you started. Your requirements are more complicated than anything I have tried so far.
|
|
|
|
|
I read this article:
http://www.codeproject.com/aspnet/PagingLarge.asp[^]
I'm developing a multi-user community site which will host many hundreds of thousands of users. The paging will be implemented in search pages (user search), mailbox, etc etc.
What are your thoughts on this article? I was told that using temp table would actually be more scalable, but the author of the article seems to rule it out completely.
|
|
|
|
|
|
Can an evaluation copy of SQL2000 Reporting Services be used for installing the Report Server Components on Windows XP Pro on which an SQL 2000 Server (not the MSDE)is installed?
|
|
|
|
|
I wanted to know if there was a way to create typed datasets by manipulating the xsd file manually and adding elements to it that in turn constitute datatables and datarows.
I know how to do it by connecting to a database and dragging tables on the xsd form.
The reason i want to do this is that I want to use this dataset to generate reports using Crystal Reports which works only with Strongly Typed Datasets. Also all my data is produced by the program and is not stored in the db but exists in various collection objects.
|
|
|
|
|
Sure there is a way, and you probably missed it just because it's so easy. Just right-click and 'Add New Item' to your project in the Solution Explorer, select 'XML Schema' on the list and name your new typed dataset class. This will present the designer, and all you have to do then is drag elements from the Toolbox (or right-click and select the items you wish to add from the context menu). You can add constraints and relations the same way. Once you have the schema set up just add a new DataSet component to your form and select your schema as the desired type.
I think this is a great way to handle and present even program data that does not reside in a 'database' because you can take advantage of all of the great data binding features, Crystal Reports, etc. Another feature I use a lot is to save the data to an XML file using DataSet.WriteXml (and DataSet.ReadXml to bring data back in), which saves having to write your own code to persist data to disk (or wherever).
Hope this helps,
Mitchell
|
|
|
|
|
I almost feel stupid that i asked that question. Thanks anyways!
|
|
|
|
|
OK, How can I make a SUM statement evaluate to NULL if one of the SUM'd records is NULL? Or an equivalent of course...
I have a table with four fields, we'll call them id, date, time, readvalue. Id is a foreign key to a table holding meter information to which the reading pertains. Each meter belongs to a site, and a site can have between 1 and 10 meters. Using SUM and GROUP BY I can create aggregate SUM information. The problem is that a missing read value is represented by a NULL, (as 0 could be a valid read value, as can both negative and positive values), and for each date and time period if one meter belonging to a site has a NULL read value, the site level date/period read value should be derived as NULL. In case you want to know, there are 96 read periods in a day, (1/15 minutes)
Table Structure
MeterId ReadDate TimeIndex ReadValue
int datetime int decimal(19,10)
Aggregating Query
<br />
select<br />
m.SiteLevelId,<br />
mr.ReadDate,<br />
mr.TimeIndex,<br />
SUM(mr.ReadValue) as 'SiteReadValue'<br />
from<br />
MeterReadingTable mr INNER JOIN MeterTable m ON mr.Id = m.Id<br />
group by<br />
m.SiteLevelId,<br />
mr.ReadDate,<br />
mr.TimeIndex<br />
GO<br />
SiteLevelId is a foreign key on the meter table, referencing the site to which it belongs, (one to many as a site can have many meters)
Any idea's?
I'd like to avoid using a cursor, which I'm sure I could to get around this, as it's going to be pretty convoluted and probably very innefficient if I go that route.
Rhys
A bus station is where a bus stops. A train station is where a train stops. On my desk I have a workstation...
Vampireware /n/, a project, capable of sucking the lifeblood out of anyone unfortunate enough to be assigned to it, which never actually sees the light of day, but nonetheless refuses to die.
|
|
|
|
|
No worries - solved it
Rhys
A bus station is where a bus stops. A train station is where a train stops. On my desk I have a workstation...
Vampireware /n/, a project, capable of sucking the lifeblood out of anyone unfortunate enough to be assigned to it, which never actually sees the light of day, but nonetheless refuses to die.
|
|
|
|
|
Try to use case :
SUM( case when len(mr.ReadValue)=0 then 0 else mr.ReadValue end )
hope it helpful.
James
|
|
|
|
|
Doesn't quite do what I want. for info. this works...
<br />
select <br />
case when count(mr.ReadValue) = count(*) then <br />
sum(mr.ReadValue) <br />
else <br />
null <br />
end <br />
as 'SiteReadValue'<br />
|
|
|
|
|
put isnull( mr.ReadValue,0)...tobe as follow;)
select
m.SiteLevelId,
mr.ReadDate,
mr.TimeIndex,
SUM(isnull( mr.ReadValue,0)) as 'SiteReadValue'
from
MeterReadingTable mr INNER JOIN MeterTable m ON mr.Id = m.Id
group by
m.SiteLevelId,
mr.ReadDate,
mr.TimeIndex
GO
keepSmile
|
|
|
|
|
I would like to create a SQL database with password and username, but when i do this i get the message "User not associated with a trusted SQL server connection". I read some FAQ:s on the net and all of them said something of mixed mode. So i changed the SQL server to mixed mode from the registry according the instructions on MSDN. But i still get this message (everything works fine with windows integrated security).
Can someone please advice?
|
|
|
|
|
Hi, I wrote an SP and select command of this SP is written to a parameter (@SqlString). there is a lot of if statement that can change the @SqlString.. how can I execute this select command in SP? (exec @SqlString doesn't work
|
|
|
|
|
|
|
I came across one article on data access layer design pattern. It was to show how to separate data access into layers such that one can easily switch between different:
1. OR Mapping tools, for instance: from NHibernate to ObjectSpace
2. Database vendor
I didn't read the article in detail, but I can't remember where to find the article now....
Norman Fung
|
|
|
|
|
Hello,
I've got two databases and need to copy one table to the another database. The table doesn't exist in the target DB, so I need a table with all columns etc.
Are there any fast solutions or must I get all values and create the sql command?
|
|
|
|
|
What DB are you using. You can use the DTS in SQL Server.
<italic>Work hard and a bit of luck is the key to success. You don`t need to be genius, to be rich.
|
|
|
|
|
I have a mdb database.It has a password (123456), i found out password with a password cracker program. I exactly dont know why this password exist . I try to connect this database via VB.Net, OLEDB Connection. My Connection string is "Provider=Microsoft.Jet.OLEDB.4.0;Password=123456;Data Source=C:\Documents and Settings\creek\Desktop\AC115DataBase.mdb; Mode=Read;Persist Security Info=True"
i cant connect to database with this connection string. I get this error "Application cannot be started. Work File is missed, or any user opened file excluesive mode"
i dont know user name or any extra information about mdb file. I am so confused.
Question is What is wrong,
|
|
|
|