Hi

Please hang on with me on this one, I would appreciate any advice or insight please....

I come from a coldfusion background, where setting up a connection to a database (Oracle, MYSQL SQL Server etc) was was easy as filling in a few fields in the datasource screen in the Coldfusion Administrator web app.

Then in the web application to connect to the database I would use <CFQUERY datasource="oracledb" name="test"> and in the body of the application I would write my SQL query and display the results of this query in a <CFOUTPUT>#variablename#</cfoutput> block of code, or to insert data into a db table I would use the

<CFQUERY datasource="oracledb" name="insertdata"> 

 INSERT INTO table (columnname, columnname2, columnname3) 
  VALUES (
    <cfqueryparam cfsqltype="cf_sql_number" value="#columnname#">,
    <cfqueryparam cfsqltype="cf_sql_varchar" value="#columnname2#">,
 <cfif isdefined("file.serverFile")>'#file.serverFile#'<cfelse>NULL</cfif>,
</cfquery>

How does this process work in .NET? as I have to create a simple web application/form where on submission of the form the data would be stored in a MYSQL database.

Sorry if its a simple question but from what I have seen so far it seems a far more long winded and complicated process with .NET over Coldfusion with ultimately the same result, and I am desperately trying to understand how it works in .NET as surely it must be a similar process to that of Coldfusion?

Recommended Answers

All 2 Replies

In .net framework, ADO.NET class library's classes (provider classes) are used. To use these classes you may choose VB.NET or C# language.

Do you have any examples of how you would do this in VB using the latest .NET process

Because as I said insertinf data with Coldfusion was a breeze. I know that .NET was basically created as a platform for professionals with a non web background to create web applications but it seems to me that because of this the process in .NET to do a database insert of data is very complex compared to Coldfusion.

For example is this the most up to date efficient approach or are there better ways to insert data into an Oracle db?

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Try
Dim DBConn As New OleDbConnection(ConfigurationManager.ConnectionStrings("PString").ToString)
Dim strQuery As String = ""
Dim DBcmd As OleDBCommand
strQuery = "INSERT INTO TABLENAME (COLUMN1, COLUMN2, COULUMN3, COULMN4, " & _
" COLUMN5,..........etc) " & _
"VALUES (TABLE.NEXTVAL,':COLUMN1VALUE', ':COLUMN2VALUE', ':COLUMN3VALUE', ':COLUMN4VALUE', " & _
" ':COLUMN5VALUE')"


DBcmd = New OleDBCommand(strQuery, DBConn)

DBcmd.Parameters.Add("COLUMN1", OleDbType.VarChar).Value = DataSet1.FieldValue("COLUMN1", Container)
DBcmd.Parameters.Add("COLUMN2", OleDbType.VarChar).Value = DataSet1.FieldValue("COLUMN2", Container)
DBcmd.Parameters.Add("COLUMN3", OleDbType.VarChar).Value = DataSet1.FieldValue("COLUMN3", Container)
DBcmd.Parameters.Add("COLUMN4", OleDbType.VarChar).Value = DataSet1.FieldValue("COLUMN4", Container)
DBcmd.Parameters.Add("COLUMN5", OleDbType.VarChar).Value = DataSet1.FieldValue("COLUMN5", Container)

DBConn.Open()

DBcmd.ExecuteReader()

DBConn.Close()
Catch ex As Exception
Response.Write("Error")
End Try
End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.