Home All Groups Group Topic Archive Search About

Re: Mixing System.Data.OleDb calls with System.Data.SqlClient calls ??

Author
4 Apr 2006 7:10 PM
Jim Hughes
Not in this scenario. SQLCommand and SQLParameter are specific to Microsoft
SQLServer.

For Access, you will want to use OleDBCommand and OleDbParameter.

You can have a SQLConnection and OleDBConnection in the same class, each
connecting to the appropriate database type.

Show quote
"glenn" <gl***@discussions.microsoft.com> wrote in message
news:2BB66E5F-6254-494C-A796-8CEE2A20C198@microsoft.com...
>I have imported the subject libraries at the top of my page's code.
>
> Using the following code, I get a cast invalid error message.  Should I be
> able to mix calls from these two different libraries?
>
> Thanks for any replies
>
>    Sub DataGrid1_UpdateRow(sender As Object, e As
> DataGridCommandEventArgs)
>
>      'Make sure the Page is Valid
>      If Not Page.Isvalid Then Exit Sub
>
>      'Get information from columns...
>      'Dim rfiNum as Label = e.Item.Cells(0).FindControl
>      Dim questionTextBox as TextBox =
> e.Item.Cells(1).FindControl("txtQuestion")
>      Dim contractTextBox as TextBox =
> e.Item.Cells(2).FindControl("txtContract")
>      Dim fromTextBox as TextBox = e.Item.Cells(3).FindControl("txtFrom")
>      Dim dateSent as Calendar = e.Item.Cells(4).FindControl("calDateSent")
>      Dim toTextBox as TextBox = e.Item.Cells(5).FindControl("txtTo")
>      Dim timeToAnsText as TextBox =
> e.Item.Cells(6).FindControl("timeToAns")
>      Dim answerText as TextBox = e.Item.Cells(7).FindControl("answer")
>      Dim projectTxt as TextBox = e.Item.Cells(8).FindControl("project")
>      Dim contractorTxt as TextBox =
> e.Item.Cells(9).FindControl("contractor")
>      Dim dateAns as Calendar = e.Item.Cells(10).FindControl("calDateAns")
>
>      Dim iID as Integer = DataGrid1.DataKeys(e.Item.ItemIndex)
>
>      'Update the database...
>      Dim strSQL as String
>      strSQL = "UPDATE rfi SET question = @questionParam, contract =
> @contractParam, from = @fromParam, datesent = @dateSentParam, to =
> @toParam,
> timetoans = @timeToAnsParam, answer = @answerParam, project =
> @projectParam,
> contractor = @contractorParam, dateans = @dateAnsParam WHERE id =
> @IDParam"
>
>      Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole
> DB Services=-4; Data Source=c:\fdmgmt\webfiles\database\fdmdb.mdb"
>      Dim dbConnection As IDbConnection = New
> OleDbConnection(strConnString)
>
>      Dim objCmd as New SqlCommand(strSQL, dbConnection)
>
>      Dim questionParam as New SqlParameter("@questionParam",
> SqlDbType.VarChar, 2000)
>      Dim contractParam as New SqlParameter("@contractParam",
> SqlDbType.VarChar, 50)
>      Dim fromParam as New SqlParameter("@fromParam", SqlDbType.VarChar,
> 50)
>      Dim dateSentParam as New SqlParameter("@dateSentParam",
> SqlDbType.DateTime, 12)
>      Dim toParam as New SqlParameter("@toParam", SqlDbType.VarChar, 50)
>      Dim timeToAnsParam as New SqlParameter("@timeToAnsParam",
> SqlDbType.VarChar, 50)
>      Dim answerParam as New SqlParameter("@answerParam",
> SqlDbType.varchar,
> 2000)
>      Dim projectParam as New SqlParameter("@projectParam",
> SqlDbType.varchar, 50)
>      Dim contractorParam as New SqlParameter("@contractorParam",
> SqlDbType.varchar, 50)
>      Dim dateAnsParam as New SqlParameter("@dateAnsParam",
> SqlDbType.DateTime, 12)
>      Dim IDParam as New SqlParameter("@IDParam", SqlDbType.Int, 4)
>
>      questionParam.Value = questionTextBox.Text
>      objCmd.Parameters.Add(questionParam)
>
>      contractParam.Value = contractTextBox.Text
>      objCmd.Parameters.Add(contractParam)
>
>      fromParam.Value = fromTextBox.Text
>      objCmd.Parameters.Add(fromParam)
>
>      dateSentParam.Value = dateSent.SelectedDate
>      objCmd.Parameters.Add(dateSentParam)
>
>      toParam.Value = toTextBox.Text
>      objCmd.Parameters.Add(toParam)
>
>      timeToAnsParam.Value = timeToAnsText.Text
>      objCmd.Parameters.Add(timeToAnsParam)
>
>      answerParam.Value = answerText.Text
>      objCmd.Parameters.Add(answerParam)
>
>      projectParam.Value = projectTxt.Text
>      objCmd.Parameters.Add(projectParam)
>
>      projectParam.Value = projectTxt.Text
>      objCmd.Parameters.Add(projectParam)
>
>      contractorParam.Value = contractorTxt.Text
>      objCmd.Parameters.Add(contractorParam)
>
>      dateAnsParam.Value = dateAns.SelectedDate
>      objCmd.Parameters.Add(dateAnsParam)
>
>      IDParam.Value = iID
>      objCmd.Parameters.Add(IDParam)
>
>      'Issue the SQL command
>      dbConnection.Open()
>      objCmd.ExecuteNonQuery()
>      dbConnection.Close()
>
>      DataGrid1.EditItemIndex = -1
>      BindData(ViewState("SortExpr"))
>    End Sub
>

AddThis Social Bookmark Button