How to retrieve data from the html table? - asp.net

I will generate html table dynamically with some textbox and dropdownlist, user will enter their input in that. How to read these data in the controller?(MVC)

There is a relatively quick and easy way to get data from a well-formatted HTML table using the Microsoft .NET Framework Data Provider for OLE DB. Essentially, this allows you to specifiy a connection string which points at the page with your HTML table on it.
Here's an example connection string:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=http://www.your_web_address.com/yourHTMLTablePage.htm;Extended Properties="HTML Import;HDR=YES;IMEX=1"
You can the use the OleDbConnection and OleDbCommand objects to get to the data contained within the table. You can find these inside the namespace: System.Data.OleDb
I hope this helps?
/Richard.

Related

Trying to understand how ASP.NET .XSL gets/saves data to/from a database

This is probably a old topic. I have an older ASP.NET application that I'm charged with modifying. I've not used this technology before. I see in the .xls files, things like <xls:value-of select="..." /> which seems to return values from the database.
I've done some searching but keep coming up with nothing relevant. Prolly because I'm using the wrong search strings. I have access to the database and the .xsl files but there's no .xml files or .xslt files in the project that I have (no project files either for that matter). Other than "<xls:value-of... />", I've no idea how the data in the database gets to the web page. Any help is appreciated.
not really sure what to suggest here. This suggests that the dataset designer was used. How this works is REALLY very much like EF (entity frameworks). The dataset designer is a typical ORM (Object relational management system).
In fact, using the dataset designer is VERY much like using EF.
However, the dataset designer does NOT let you set/use a database connection string.
(you choose one WHEN creating the dataset). But you no doubt have a defined connection anyway. If you change that connection string, then the dataset designers will now use that changed connection string anyway.
Like EF? Well, do you really care much how it works, or do you just care that you have the tables as some data model? I tend to not care anything more then
Hey, do I have a table - can I use it? can I feed the results to say a gridview or some such? So in effect, what you REALLY care about is how to use those data objects in code.
So, then you don't care if the database is Oracle, MySQL, SQL server, or even MS-Access.
When you open/launch say a xsd file in vs? the dataset desinger should launch.
So, You see this:
So, the above is 100% the SAME regardless of the actaual database being used. As noted, it could be MS-Access or Oracle - I don't care. In BOTH cases or in fact regadless of the database enigne, I will STILL get the above, and NOT have to change my code or care about the database in question.
So, we can for example write out in code to fill a grid view. (that's what we often call database first, or simply that we don't use EF, or the older datasets - which I noted are the same idea).
So, say I drop a grid view onto a page.
So, to fill the Grid, I might have this
(just code - no EF or Dataset designer used).
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
LoadGrid
End If
End Sub
Sub LoadGrid()
Using conn As New SqlConnection(My.Settings.TEST4)
Dim strSQL As String =
"SELECT TOP 10 FirstName, LastName, HotelName, City, Description
FROM tblHotels ORDER BY HotelName"
Using cmdSQL As New SqlCommand(strSQL, conn)
conn.Open()
GridView1.DataSource = cmdSQL.ExecuteReader
GridView1.DataBind()
End Using
End Using
End Sub
And now I have this:
But, in place of typing in specific sql server syntax, and building that data table in code?
I would consider using EF or the older dataset designer.
so, I can add a new query in the dataset designer.
So, now we have a really nice "central" means to see our database schema, and a nice central place to say add queries and manage the data model.
This means I don't have in-line SQL tossed around in the code base like spaghetti.
So adding store procedure methods (with parameters), general queries, and a REALLY nice 50,000 foot view of the data model is why we use EF , or the older dataset designer. This so called ORM approach is common used.
So, now the above code, say based on my dataset, and that query I added to/in the dataset designer? I can now use that one query over and over in code.
I added the new query and called it GetMyHotels
So, now my code to fill the grid view becomes this:
Dim Mydt As New TEST4TableAdapters.tblHotelsTableAdapter
GridView1.DataSource = Mydt.GetMyHotels
GridView1.DataBind()
And I even get intel-sense for "GetMyHotels"
So, you don't now mess with SQL or even connection strings in code. You have a "object" that is your database.

How to send datatable as a parameter to mysql store procedure through asp.net code

How to send datatable as a parameter to mysql store procedure through asp.net code.
if any solution is there, can anyone please tell me. Its urgent
thank you,
You could write it to a .csv and use LOAD DATA INFILE
- LOAD DATA INFILE Syntax
Else you you have to loop through the datatable and insert one by one row.
References
Best way to Bulk Insert from a C# DataTable
I would parse the data set and for each data row call a stored procedure passing parameters for one data row. If you don't want that, then there are other import facilities (bulk import) like http://brockangelo.com/2009/04/27/how-to-bulk-import-into-a-mysql-database or MySQL bulk insert from CSV data files.

Using a SQL Function to Format Account info?

I have a SQL function that I am calling in my VB.Net code within a display function. The SQL function will format my account data to include the following results form a Table.
The table data: "001000011121" (this is the type of structure the data has before formated)
So the data table data and vb Properties would be called Myaccount, HerAccount, ThisAccount.
Once the data is pulled and then formatted in the VB.net code it will result into a GridDisplay as as: "001.00.001.1121"
The way I have my Public Function in my code is:
Public Funcion GetDisplay(_
ByVal dbBass as DataProvider_
,ByVal pps AS TMGDatarequestParms_
,By filter As IFilter_
) As Ilist
Dim strobe As String = CType(parms.OptionalParameters, DataProvider).Database
Dim sql As BiGSqlBuilder(TABLE)
sql.Select = String.Format("ID, [{0}].dbo.GLForamtAcct(Myaccount) AS [Myaccount], [{0}].dbo.GLFormatAccount(HerAccount) AS [HerAccount], [{0}].dbo.GLFormatAccount(ThisAccount) AS [ThisAccount]", strobe)
I left out some of the return code since not necessary. The only thing I'm concerned is how to format the SQL within the VB.net Code above. I hope this makes sense I'm new to this whole abstraction stuff. Any help would be Highly appreciated cause I'm pretty sure how I have it above does not work.
Suggest implementing your display code in your higher tiers, rather than burdening your database with this business logic.
It sounds like you're string to use String.Format() to insert the table name in your string. This syntax of database.schema.object is really only needed if performing cross database calls.
If you really want to use your SQL UDF to perform your formatting, suggest using/formulating a SELECT statement like:
SELECT ID,
dbo.GLFormatAccount(Acct1) AS Acct1,
dbo.GLFormatAccount(Acct2) AS Acct2,
dbo.GLFormatAccount(Acct3) AS Acct3
FROM MyTable

Cannot insert null where field is Guid (object in SqlDataSource)

I have a table which links to another table in the ASP.NET membership schema.
Problem is, all the PKs for the ASP.NET tables are uniqueidentifier so mine has to be too. When I add a SqlDatasource and call its Insert() method, I get the following error:
Cannot insert the value NULL into column 'DiscountCode', table 'CreamDb.dbo.CustomInfo1'; column does not allow nulls. INSERT fails.
The statement has been terminated.
The uniqueidentifier is also treated as an object (its data type), but there is no Guid data type. I had this problem before, but the schema was much simpler so I could fix it.
How can I go about fixing this? If I get rid of the data type part in the markup (so just leave the field/parameter name but not the data type stuff), I get another error so that is not possible.
Thanks
What do you mean by "there is no Guid data type"? What's wrong with System.Guid? Can't you just use Guid.NewGuid(), set the field appropriately, and do the insert?
EDIT: Just to give a bit more meat: attach an event handler to the Inserting event, and populate the field then, via the DbCommand returned by SqlDataSourceCommandEventArgs.Command. Or change the SQL used by the INSERT command to ask the database to populate the GUID field for you.
A popullar approach when dealing with references to the ASP.NET Membership Provider's data is, instead of keeping a proper foreign key to the GUIDs, instead store something like the LoweredUserName in your table. Then, use the Membership Provider's API to interact with the object you need. In some cases, you need an ObjectDataSource abstraction layer to accomplish CRUD scenarios.
Set the default value of the column in SQL Sever to "newid()".
Asp.net won't send the value, and the field will get a new guid.

XML to Database in ASP.NET

Using VB.NET, how do I add the values from an XML file into an SQL Server database with a similar schema?
I don't know the methods off the top of my head but you ought to be able to load the file into a DataTable and then use ADO.net to get it into the database (look into the SqlBulkCopy class if you're using a SQL Server DB).
This ought to get you enough words to punch into and find a good example.
Easiest way is using the DataSet class's ReadXml() method. Then, as the user above mentions, the dataset contains one (1) DataTable. It's pretty easy to get that into SQL.
Use an XSL Transform to create an insert statement.
can't use xsl transform, you need a string for query, not another xml

Resources