|
Hi,
I actually never use typed datasets since in my opinion they lack very much functionality when you want to do anything "more complex" (but I had to give it a try in this case ).
I understood that the problem isn't in creating the typed dataset, but how to build the form so that when you click on the first datagridview (or some other control) which represents the parent table, how to design the UI so that the child datagridview automatically shows the records corresponding to the selected parent row?
If that was correct, the trick is that when designing the second datagridview you define the datasource as the foreign key from the first binding source.
First bind the parent datagridview normally. Then when binding the child datagridview open the datasource combo and you should see a plus sign before the previously created bindingsource (for the parent datagridview) object. When you expand that, you should see the foreign key name defined in the typed dataset. Select it as datasource. After that you're able to select stuff from the child table and it should work.
|
|
|
|
|
Thanks Mika, I should try that now and if it works, it is exactly what I need so thanks again mate
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
No problem If you have time after testing it, drop a post and tell how it went.
|
|
|
|
|
Hey Mika,
It's finally working! Thanks to you and a couple of modifications.. You know what, I think I'll have to share my experience in an article cuz it's a bit tricky to explain without pictures, I think what makes it difficult is that database I'm working with is Oracle God I'm sorry Mika but I think my bird is dying!! I'll let you know when I have this article ready!
Many thanks Mika.. Please pray for my bird
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
Muammar© wrote: I think what makes it difficult is that database I'm working with is Oracle
Don't quite understand why it would be any more difficult than with SQL Server or any other database because you're still using datasets. Perhaps something in the data model?
Muammar© wrote: I'll let you know when I have this article ready
That would be nice
Muammar© wrote: Many thanks Mika..
No problem at all.
Muammar© wrote: Please pray for my bird
I will!
|
|
|
|
|
|
Hi All,
I have two tables like Casual_Employee_Details, Permanent_Employee_Table and the columns in both tables are same.
I have a stored procedure as follows
CREATE PROCEDURE getEmpId
(
@Eid int,
@EName varchar(50)
)
AS
insert into Casual_Employee_Details(n_EmpId,c_EmpName)values(@EmpId,@EmpName)
GO
Now i want to pass table name also dynamically how can it be done.
help me out with code if possible..
So that if if i execute it should as follows
Execute dbo.getEmpId 'tableName',Eid,'Ename'
Thanks,
Ashok
ashok
|
|
|
|
|
you have to concatenate the whole sql string to a variable like
set @sql = 'insert into ' + QUOTENAME(@tablename)
+ ' (n_EmpId,c_EmpName)values('
+ convert(varchar(50), @EmpId)
+ ',' + QUOTENAME(@EmpName, '''') + ')'
exec (@sql)
However it's not typically a good idea to use dynamic sql this way. It may lead to several problems.
Modification, added QUOTENAME to prevent injections.
|
|
|
|
|
Mika Wendelius wrote: However it's not typically a good idea to use dynamic sql this way
It is posslble to do some verification before you start the concatenation. For instance. you can look up INFORMATION_SCHEMA.TABLES to ensure that the a table with the given name exists. If it doesn't you can exit the sproc.
You can also pass parameters to dynamic SQL by using sp_executesql[^] instead of EXEC . That way you are not concatenating potentially dangerous data into the SQL String, you're passing it as a parameter as normal.
|
|
|
|
|
You're right, there are numerous ways to perform checks and prevent injections etc. but since I wasn't sure why the OP wanted to use dynamic sql for the insert (it didn't quite make sense since for example columns were hardcoded) I thought it would be wise if he thinks about it once more.
If dynamic handling for the table name is still required, at least it's thoroughly considered.
I just noticed that I forgot to use QUOTENAME. Think I should add it to the answer. Another way is to use sp_executesql as you mentioned.
|
|
|
|
|
Hi all,
Can anyone explain other possible mechanisms to handle this scenario in detail.
Any references could be helpful..
thanks,
Ashok
ashok
|
|
|
|
|
ashok_rgm wrote: Can anyone explain other possible mechanisms to handle this scenario in detail
As Colin and I wrote you can use either sp_executesql or exec to execute a dynamic sql statement. Both will do as long as you prevent yourself from sql injections.
In your original post you described that you want to pass the table name as a parameter and use it in your sql statement. However your column names were hardcoded in the statement so it makes me wonder, why do you want to change the table name. First impression is that you have several tables with the same structure. If that's correct then again, why?
|
|
|
|
|
My issue is something like this
i have a table Master_Info with columns(RecId(PK),Emp_Name,DOB) where RecId is primary key and increments by 1 for each entry.
RecId Emp_Name DOB
1 abc 01/01/2009
2 xyz 02/02/2009
Now for each Employee I have separate table to track hi daily details Employee_Details_(RecId) with columns (Working_Date,No_of_Hours)
So for user "abc" the table name will be Employee_Details_1,for "xyz" it will be Employee_Details_2
Now I want to insert the records for particular user in Employee_Details_(RecId) table using the stored procedure.
What are the suggested ways to do this task?
Thanks,
Ashok
ashok
|
|
|
|
|
ashok_rgm wrote: Now for each Employee I have separate table to track hi daily details Employee_Details
Is there really a very good reason to do it this way?
Normally you would have a table structures like:
Master_Info
- RecId (primary key)
- Emp_Name
- DOB
Employee_Details
- ID (primary key)
- RecId (foreign key to Master_Info)
- Working_Date
- No_of_Hours
So in Employee detail you store details for all employees and the RecId column tells which employee is referenced.
|
|
|
|
|
I am running 64-bit Vista Ultimate.
1. Do 32-bit applications require 32-bit ODBC drivers, and 64-bit applications require 64-bit ODBC drivers?
2. How can I administer the 32-bit ODBC drivers on my system? Whenever I run the ODBC Administrator applet, it only shows me the 64-bit drivers.
Thanks
|
|
|
|
|
Richard Andrew x64 wrote: 1. Do 32-bit applications require 32-bit ODBC drivers, and 64-bit applications require 64-bit ODBC drivers?
In case of ODBC drivers, 32-bit require 32-bit odbc drivers only and same for 64 bit.
Richard Andrew x64 wrote: 2. How can I administer the 32-bit ODBC drivers on my system?
You need to figure it out manually
|
|
|
|
|
I have a stored procedure , that imports the data to sql server 2005, For that I send the XML
to database, there I extract the data and insert/update it in one query.
I am operating the same thing at multi user level and starts multi users start the import
for the central localized database, there I am watching the execution in sql profiler,
and now my problem is
The Audit logout/login takes lot of time to execute,
Suppose two users are simultaneously doing the import process, if the first user reaches the
database first, there after the completion of the import for the first user,
still the request of first user does not complete , it
remains there for several minutes until audit logs out.
and due to this the second user keep waiting for the import execution.
please provide suggestion for this performance issue.
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
|
|
|
|
|
Is there some reason why you suspect that audit log is the rason for waiting? If both of the users are adding data to the same table, I would guess that the second session is waiting for exclusive locks to release from the first session. Have you used current activity window in Management Studio to see what the second session waits?
|
|
|
|
|
I'm a beginner C#/ASP.NET programmer (long time C/C++ in Unix programmer) having problems with storing an image on my webform to sql then retrieving it. Problem is, I've got the image on my webform along with other information in textboxes that need to be stored in the database. All the textbox info as well as two images on the webform (the images are signatures captured from signature pads) need to be stored then later recalled to bring up a print preview of the information that was earlier saved. All my textbox info is being stored and recalled properly, but I'm having issues with the images of the signatures. There's no real file for the image to upload via a dialog box, just the captured image. Can anyone help me out?
Thanks
|
|
|
|
|
You can store the image data in byte[] and use SqlParameter with type VarBinary. Although it's not exactly what you ask, you could look at the sample project in the article http://www.codeproject.com/KB/database/SqlFileStream.aspx[^]. SqlFileStream isn't included in SQL Server 2005, but in the example project one of the variations is normal SqlParameter usage.
|
|
|
|
|
I figured I'd need to convert the image data to byte[] from what I've been finding when looking for a solution, but I'm not sure how to go about that in C#. Like I said, I'm a newbie at this .NET stuff. The signature images I need to store to (and then later retrieve again from) SQL are System.Web.UI.WebControls.Image. Also, my database table already has a row entry, so storing the images are going to be an update into that row, rather than an insert.
|
|
|
|
|
I'm not very familiar with web controls, but I take it you set the imageurl to point to a file? If yes, then you could just read that file using File.ReadAllBytes .
roachae wrote: my database table already has a row entry, so storing the images are going to be an update into that row, rather than an insert
If you mean the example in the article which inserted a record, you would simply use an UPDATE statement instead of an INSERT statement. Something like:
UPDATE SomeTable
SET ImageColumn = @Image
WHERE KeyColumn = @Key
|
|
|
|
|
The only file I have is of a default blank image. Like I said, the images are of signatures captured from a signature pad, so there's no real file there until someone signs the signature pad and the image is placed within the webform. But even my default blank image will not store properly. How would I use File.ReadAllBytes? I'm not finding that anywhere.
As for using UPDATE in place of INSERT, I got that much figured out as most of my other data is being saved by UPDATE. I've got a bit of experience working in PHP and MySQL, but this is the first project I've worked on in C#/ASP/SQL Server. And I've never dealt with images before.
|
|
|
|
|
roachae wrote: Like I said, the images are of signatures captured from a signature pad, so there's no real file there until someone signs the signature pad and the image is placed within the webform
Where does the image data come from in this situation? I didn't find any property in Image control that contains the actual image data, only the Url property. However, as I said, I'm not very familiar with Asp.Net controls.
roachae wrote: How would I use File.ReadAllBytes? I'm not finding that anywhere
File.ReadAllBytes Method[^]
If I remember correctly I used that method in the example project in the article. Have a look at the DbOperations class and method StoreFileUsingSqlParameter. That should contain almost everything you need except that you have to use UPDATE.
|
|
|
|
|