Advertisement

07.25.2008 at 01:42PM PDT, ID: 23596776
[x]
Attachment Details

SqlDataAdapter Insert How To

Asked by kenholm3 in Programming for ASP.NET, Microsoft Visual Basic.Net

Tags: asp.net vb

I can run the listed code.  While no errors occur no data is pushed into the database either.  I am able to run Selects via SqlDataAdapter in a like way.  What is glaringly wrong?

Better yet... What code will allow me to use SqlDataAdapter to INSERT data into a table?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
Public Function SaveDelegate(ByVal _pid As String, ByVal _delegate As String, ByVal _expiry As String) As Boolean
        Dim _myDataAdapter As New SqlDataAdapter("select * from delegates", _dbConnection)
        Dim _mySqlCommand As New SqlCommand("insert into delegates (myPid, delegatePid, fallbackPid, expires) values (@pid, @delegate, @delegate, convert(datetime, @expiry))", _dbConnection)
        Dim _myDataSet As New DataSet()
        Dim _returnValue As Boolean = False
 
        _dbConnection.Open()
 
        _myDataAdapter.Fill(_myDataSet, "delegates")
 
        Dim p As New SqlParameter("@pid", SqlDbType.NVarChar, 10)
        Dim d As New SqlParameter("@delegate", SqlDbType.NVarChar, 10)
        Dim e As New SqlParameter("@expiry", SqlDbType.DateTime)
 
        _mySqlCommand.Parameters.Add(p)
        _mySqlCommand.Parameters.Add(d)
        _mySqlCommand.Parameters.Add(e)
 
        _myDataAdapter.InsertCommand = New SqlCommand(Nothing, _dbConnection)
        With _myDataAdapter.InsertCommand
            .CommandText = "insert into delegates (myPid, delegatePid, fallbackPid, expires) values (@pid, @delegate, @fallBack, convert(datetime, @expiry))"
            .Parameters.Add(New SqlParameter("@pid", SqlDbType.NVarChar, 10, "myPid"))
            .Parameters("@pid").Value = _pid
 
            .Parameters.Add(New SqlParameter("@delegate", SqlDbType.NVarChar, 10, "delegatePid"))
            .Parameters("@pid").Value = _delegate
 
            .Parameters.Add(New SqlParameter("@fallBack", SqlDbType.NVarChar, 10, "fallbackPid"))
            .Parameters("@pid").Value = _delegate
 
            .Parameters.Add(New SqlParameter("@expiry", SqlDbType.DateTime, 10, "expires"))
            .Parameters("@pid").Value = _expiry
 
        End With
 
        _myDataAdapter.Update(_myDataSet, "delegates")
 
        _dbConnection.Close()
 
        Return (_returnValue)
    End Function
[+][-]07.25.2008 at 05:42PM PDT, ID: 22093167

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Programming for ASP.NET, Microsoft Visual Basic.Net
Tags: asp.net vb
Sign Up Now!
Solution Provided By: ororiole
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.28.2008 at 04:14AM PDT, ID: 22102056

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628