Solved

Send Dataset to Webservice!!Urgent please help

Posted on 2004-08-07
12
417 Views
Last Modified: 2012-06-27
Hi,
I'm faced with the following problem:

1) I'm trying to send some information from a client to a webservice. Now, this information happens to be a dataset which contains all the data in a table(select * query).
Problem/Question: Can i send a DATASET to the webservice as a parameter??? If so, how??
Qn 2: If i send the dataset to the webservice is it possible for me to create a relational table on the web service's side with the data set that has been passed by the client.

Please help....It is very urgent and i'm clueless as to how to proceed.

Thanks,
0
Comment
Question by:srik18
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
0
 
LVL 37

Expert Comment

by:gregoryyoung
Comment Utility
actually aeros thats backwards, thats consuming a dataset from a webservice.

you would just pass a dataset to the method as normal ...

public function Whatever(byval ds as DataSet)
end function


then you are asking to create a relational table ... do you mean to create a table in your database based on the dataset ?

0
 

Author Comment

by:srik18
Comment Utility
Hi Guys,
Thanks a lot for your quick responses.

gregoryyoung:
Yes that is right i need to construct a relational database from the dataset thats being sent to the webservice. That is this database is not currently available at the place where the webservice is available. So i need to create a database on an SQL Server based on this dataset that i am getting from the client.

I hope i am clear.

Aeros:
Thank you for the link but if i am not wrong the link explains how to update a database ASSUMING that the database is available on both the client side and the place where the webservice is located.

Hope you guys can clear my problem. :)
Thanks a lot once again.
S
0
 
LVL 37

Expert Comment

by:gregoryyoung
Comment Utility
am I right in assuming that the tables do not currently exist at the site where the webservice is ? or is it a buch of clients sending up similar data which needs to be merged ?
0
 

Author Comment

by:srik18
Comment Utility
Hi Mr.Gregory Young,
Yes, You are right. The table does not exist where the webservice is. Each client sends the FULL dataset of a particular database with each request that is, we are not merging the data at the webservice from various clients.
This dataset from a single client needs to be converted into a database.
Thanks a lot once again.
S.
0
 
LVL 37

Expert Comment

by:gregoryyoung
Comment Utility
not sure on the actual create, but once the table is there you will be using the sqlcommandbuilder object, similar to here http://www.devarticles.com/c/a/ADO.NET/Automatic-Generation-of-Single-Table-SQL-Statements-in-.NET/
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 28

Expert Comment

by:mmarinov
Comment Utility
Hi srik18,

from what you are posting i understand that you want to do things like this

1. in web service receive dataset from the client
2. in your database create a datatable based on the structure of the datatable objects in the collection dataset.tables ( is there ony one datatable in your dataset collection ? )
3. Fill the created table with the data from the dataset

is this correct ?

B..M
0
 

Author Comment

by:srik18
Comment Utility
Hi Mr.Marinov,
Yes you got it right.
What i want is
1) send dataset from client...which i have actually achieved at the moment.
2) in my database (which is at the location of webservice) create the datatable based on the objects in dataset.tables.
3) Fill the table with data from the dataset(that is recreate the same data table on the webservice side when the only information you have is the dataset.)
The dbms we are using is SQL Server.
We are currently trying to use the readXML schema and writeXMLschema methods but we are stuck at the moment...if u have any other approach or have code samples to show how this can be done that would be great.

Thanks a lot.
S.

p.s: Taking the question to another level :    
can we create a database also on the webservice side . That is suppose the client sends the name of the table and name of the database ex: customers and Northwind. Can we create a database on the webservice side named northwind and can we create a datatable in that database called customers.--> all through code.
I am of the opinion that the database cannot be created and hence i am assuming that the database is already present at the webservice side but the database does not have the datatable whose dataset the client is sending.
Hope i am clear. Sorry for the late response.
0
 
LVL 37

Expert Comment

by:gregoryyoung
Comment Utility
yes you can, although I believe you will have to write the code to create the database/table on your own. One issue that you will run into here is field sizes/precision.

0
 

Author Comment

by:srik18
Comment Utility
Hi Mr.Gregory Young,
Can you give us a code sample(that goes into the webMethod) showing us how it can be done....assuming that we give fixed(hard coded) field sizes ??
How do we create a database and datatable?
Thanks.
S
0
 
LVL 28

Accepted Solution

by:
mmarinov earned 500 total points
Comment Utility
using this statement
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='your table name' you can get the structure of the table and like this

private static string BuildStringForCreae(DataTable _dt, DataTable _dt_rows )
        {
            if ( _dt == null )
                return null;

            StringBuilder sb = new StringBuilder();

            for ( int _field_index = 0; _field_index < _dt.Rows.Count; _field_index++ )
            {
                sb.Append ( _dt.Rows[_field_index]["COLUMN_NAME"].ToString() + " " +
                    _dt.Rows[_field_index]["DATA_TYPE"].ToString());

                if (_dt.Rows[_field_index]["DATA_TYPE"].ToString() == "char"||
                    _dt.Rows[_field_index]["DATA_TYPE"].ToString() == "nchar" ||
                    _dt.Rows[_field_index]["DATA_TYPE"].ToString() == "nvarchar")
                    sb.Append (" (" + _dt.Rows[_field_index]["CHARACTER_MAXIMUM_LENGTH"].ToString() + ")");

                if ( (bool)_dt_rows.Columns[_dt.Rows[_field_index]["COLUMN_NAME"].ToString()].AutoIncrement )
                    sb.Append (" IDENTITY ( " + _dt_rows.Columns[_dt.Rows[_field_index]["COLUMN_NAME"].ToString()].AutoIncrementSeed + "," + _dt_rows.Columns[_dt.Rows[_field_index]["COLUMN_NAME"].ToString()].AutoIncrementStep + " )" );

                if ( _dt.Rows[_field_index]["IS_NULLABLE"].ToString().Trim() == "No")
                    sb.Append(" NOT NULL" );
                else
                    sb.Append(" NULL ");

                if ( _dt.Rows[_field_index]["COLUMN_DEFAULT"]!= DBNull.Value)
                    sb.Append( " DEFAULT '" + _dt.Rows[_field_index]["COLUMN_DEFAULT"].ToString() + "'");

                if ( _field_index != _dt.Rows.Count-1 )
                    sb.Append(","+Environment.NewLine);
            }

            return sb.ToString() + " ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] ";
        }

to create  your own create sql script, where
_dt is the table return by the sql statement
the _dt_rows are the rezults which will be inserted

after creating the create script, execute it and then create insert statement for every row in the _dt_rows datatable

Regards,
B..M
0
 

Author Comment

by:srik18
Comment Utility
Hi MMarinov,
Thanks a lot for the code. We are doing it in a different way but the code was helpful elsewhere....i am giving you the points. I am posting another question which i believe is relatively simple...please kindly help if you can.
Thanks a lot.
S
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now