Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default SQL INSERT error

    Any ideas on why the below doesn't work?

    I keep getting this error message????? ---> "Object must implement
    IConvertible".

    Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles cmdSubmit.Click

    'CONNECT TO SQL

    Dim strConnection As String

    strConnection = "Data Source=x.x.x.x,1433;Network Library=DBMSSOCN;Initial
    Catalog=Ops1SQL;User ID=dbIN;Password=xxxyyyzzz;"

    Dim cn As New SqlConnection(strConnection)

    '------INSERT TO BASE Work Order Table

    Dim strSQL As String



    strSQL = "INSERT INTO tblWorkOrder (FKEYDepartment, Initiator, ReceiveNOW,
    Problem)" & _

    " VALUES (@Department, @Initiator, @ReceiveNOW, @Problem)"



    Dim dbComm As New SqlCommand(strSQL, cn)

    dbComm.Parameters.Add("@Department", SqlDbType.Int)

    dbComm.Parameters.Add("@Initiator", SqlDbType.Int)

    dbComm.Parameters.Add("@ReceiveNOW", SqlDbType.DateTime)

    dbComm.Parameters.Add("@Problem", SqlDbType.NText, 16)

    dbComm.Parameters("@Department").Value = 8

    dbComm.Parameters("@Initiator").Value = CInt(Session("EmployeeKEY"))

    dbComm.Parameters("@ReceiveNOW").Value = Now()

    dbComm.Parameters("@Problem").Value = Me.txtComments



    Dim woKEY As Integer

    Try

    cn.Open()

    woKEY = dbComm.ExecuteScalar()

    Catch ex As Exception

    Me.txtAccountNumber.Text = ex.Message.ToString

    Finally

    If cn.State = ConnectionState.Open Then

    cn.Close()

    End If

    Me.txtRespCode.Text = woKEY.ToString

    End Try

    '------INSERT the sub work order

    End Sub


    Cameron Frasnelly Guest

  2. Similar Questions and Discussions

    1. Need Help with Record Insert Error
      Hi Coldfuschions, I am a novice and am trying to use the Record Insertion Form Wizard in D8/ColdFusion to add a record to a MS Access database. ...
    2. insert error
      Hi all, I have a table containing an ID (unique, autoincrement) and some other fields including IP. When I try to insert the 'ip' I get a...
    3. ERROR: Please insert CD-ROM
      Why does the program keep asking me to insert the CD? I thought I downloaded it to my harddrive but now acts like it won't work unless, I keep the...
    4. Insert error :: must be updateable?
      I am picking up the following error message which is strange as it has only started happening since I have transferred servers: Microsoft JET...
    5. asp insert error
      hi, I made a asp form to insert product in a db. on my localhost everything works just fine. But online i got the : Microsoft OLE DB Provider...
  3. #2

    Default Re: SQL INSERT error

    Oh... it fails on this line...

    woKEY = dbComm.ExecuteScalar()


    "Cameron Frasnelly" <networkmanage@premierwestbank.com> wrote in message
    news:%236RnE9fXDHA.652@TK2MSFTNGP10.phx.gbl...
    > Any ideas on why the below doesn't work?
    >
    > I keep getting this error message????? ---> "Object must implement
    > IConvertible".
    >
    > Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles cmdSubmit.Click
    >
    > 'CONNECT TO SQL
    >
    > Dim strConnection As String
    >
    > strConnection = "Data Source=x.x.x.x,1433;Network Library=DBMSSOCN;Initial
    > Catalog=Ops1SQL;User ID=dbIN;Password=xxxyyyzzz;"
    >
    > Dim cn As New SqlConnection(strConnection)
    >
    > '------INSERT TO BASE Work Order Table
    >
    > Dim strSQL As String
    >
    >
    >
    > strSQL = "INSERT INTO tblWorkOrder (FKEYDepartment, Initiator, ReceiveNOW,
    > Problem)" & _
    >
    > " VALUES (@Department, @Initiator, @ReceiveNOW, @Problem)"
    >
    >
    >
    > Dim dbComm As New SqlCommand(strSQL, cn)
    >
    > dbComm.Parameters.Add("@Department", SqlDbType.Int)
    >
    > dbComm.Parameters.Add("@Initiator", SqlDbType.Int)
    >
    > dbComm.Parameters.Add("@ReceiveNOW", SqlDbType.DateTime)
    >
    > dbComm.Parameters.Add("@Problem", SqlDbType.NText, 16)
    >
    > dbComm.Parameters("@Department").Value = 8
    >
    > dbComm.Parameters("@Initiator").Value = CInt(Session("EmployeeKEY"))
    >
    > dbComm.Parameters("@ReceiveNOW").Value = Now()
    >
    > dbComm.Parameters("@Problem").Value = Me.txtComments
    >
    >
    >
    > Dim woKEY As Integer
    >
    > Try
    >
    > cn.Open()
    >
    > woKEY = dbComm.ExecuteScalar()
    >
    > Catch ex As Exception
    >
    > Me.txtAccountNumber.Text = ex.Message.ToString
    >
    > Finally
    >
    > If cn.State = ConnectionState.Open Then
    >
    > cn.Close()
    >
    > End If
    >
    > Me.txtRespCode.Text = woKEY.ToString
    >
    > End Try
    >
    > '------INSERT the sub work order
    >
    > End Sub
    >
    >

    Cameron Frasnelly Guest

  4. #3

    Default Re: SQL INSERT error

    > dbComm.Parameters("@Problem").Value = Me.txtComments

    I think you want: Me.txtComments.Text


    "Cameron Frasnelly" <networkmanage@premierwestbank.com> wrote in message
    news:%236RnE9fXDHA.652@TK2MSFTNGP10.phx.gbl...
    > Any ideas on why the below doesn't work?
    >
    > I keep getting this error message????? ---> "Object must implement
    > IConvertible".
    >
    > Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles cmdSubmit.Click
    >
    > 'CONNECT TO SQL
    >
    > Dim strConnection As String
    >
    > strConnection = "Data Source=x.x.x.x,1433;Network Library=DBMSSOCN;Initial
    > Catalog=Ops1SQL;User ID=dbIN;Password=xxxyyyzzz;"
    >
    > Dim cn As New SqlConnection(strConnection)
    >
    > '------INSERT TO BASE Work Order Table
    >
    > Dim strSQL As String
    >
    >
    >
    > strSQL = "INSERT INTO tblWorkOrder (FKEYDepartment, Initiator, ReceiveNOW,
    > Problem)" & _
    >
    > " VALUES (@Department, @Initiator, @ReceiveNOW, @Problem)"
    >
    >
    >
    > Dim dbComm As New SqlCommand(strSQL, cn)
    >
    > dbComm.Parameters.Add("@Department", SqlDbType.Int)
    >
    > dbComm.Parameters.Add("@Initiator", SqlDbType.Int)
    >
    > dbComm.Parameters.Add("@ReceiveNOW", SqlDbType.DateTime)
    >
    > dbComm.Parameters.Add("@Problem", SqlDbType.NText, 16)
    >
    > dbComm.Parameters("@Department").Value = 8
    >
    > dbComm.Parameters("@Initiator").Value = CInt(Session("EmployeeKEY"))
    >
    > dbComm.Parameters("@ReceiveNOW").Value = Now()
    >
    > dbComm.Parameters("@Problem").Value = Me.txtComments
    >
    >
    >
    > Dim woKEY As Integer
    >
    > Try
    >
    > cn.Open()
    >
    > woKEY = dbComm.ExecuteScalar()
    >
    > Catch ex As Exception
    >
    > Me.txtAccountNumber.Text = ex.Message.ToString
    >
    > Finally
    >
    > If cn.State = ConnectionState.Open Then
    >
    > cn.Close()
    >
    > End If
    >
    > Me.txtRespCode.Text = woKEY.ToString
    >
    > End Try
    >
    > '------INSERT the sub work order
    >
    > End Sub
    >
    >

    PJ Guest

  5. #4

    Default Re: SQL INSERT error

    Use

    ExecuteNonQuery instead of ExecuteScalar

    "Cameron Frasnelly" <networkmanage@premierwestbank.com> wrote in message
    news:%236RnE9fXDHA.652@TK2MSFTNGP10.phx.gbl...
    > Any ideas on why the below doesn't work?
    >
    > I keep getting this error message????? ---> "Object must implement
    > IConvertible".
    >
    > Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles cmdSubmit.Click
    >
    > 'CONNECT TO SQL
    >
    > Dim strConnection As String
    >
    > strConnection = "Data Source=x.x.x.x,1433;Network Library=DBMSSOCN;Initial
    > Catalog=Ops1SQL;User ID=dbIN;Password=xxxyyyzzz;"
    >
    > Dim cn As New SqlConnection(strConnection)
    >
    > '------INSERT TO BASE Work Order Table
    >
    > Dim strSQL As String
    >
    >
    >
    > strSQL = "INSERT INTO tblWorkOrder (FKEYDepartment, Initiator, ReceiveNOW,
    > Problem)" & _
    >
    > " VALUES (@Department, @Initiator, @ReceiveNOW, @Problem)"
    >
    >
    >
    > Dim dbComm As New SqlCommand(strSQL, cn)
    >
    > dbComm.Parameters.Add("@Department", SqlDbType.Int)
    >
    > dbComm.Parameters.Add("@Initiator", SqlDbType.Int)
    >
    > dbComm.Parameters.Add("@ReceiveNOW", SqlDbType.DateTime)
    >
    > dbComm.Parameters.Add("@Problem", SqlDbType.NText, 16)
    >
    > dbComm.Parameters("@Department").Value = 8
    >
    > dbComm.Parameters("@Initiator").Value = CInt(Session("EmployeeKEY"))
    >
    > dbComm.Parameters("@ReceiveNOW").Value = Now()
    >
    > dbComm.Parameters("@Problem").Value = Me.txtComments
    >
    >
    >
    > Dim woKEY As Integer
    >
    > Try
    >
    > cn.Open()
    >
    > woKEY = dbComm.ExecuteScalar()
    >
    > Catch ex As Exception
    >
    > Me.txtAccountNumber.Text = ex.Message.ToString
    >
    > Finally
    >
    > If cn.State = ConnectionState.Open Then
    >
    > cn.Close()
    >
    > End If
    >
    > Me.txtRespCode.Text = woKEY.ToString
    >
    > End Try
    >
    > '------INSERT the sub work order
    >
    > End Sub
    >
    >

    Srinivas Kotipalli Guest

  6. #5

    Default SQL Insert Error

    Ok I'm having a problem with a SQL insert going to a Access database...here
    is the connection code:

    // PHP db connection
    $db = 'C:\\Phpweb\\test.mdb';
    $conn = new COM('ADODB.Connection');
    $conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");
    $query = $conn->Execute($sql);

    Here is the print out of the SQL:

    INSERT INTO
    [Cards]([active],[division],[province],[filetitle],[air],[water],[sewage],[p
    ttw],[partVIII],[part46]) VALUES ('1','ob','Ontario','0 0 0
    0','1','1','1','1','1','1')

    Here is the errors:

    Warning: (null)(): Invoke() failed: Exception occurred. Source: Microsoft
    JET Database Engine Description: Syntax error in INSERT INTO statement. in
    c:\phpweb\admin.card.view.php on line 193

    Warning: (null)(): Invoke() failed: Exception occurred. Source:
    ADODB.Connection Description: Arguments are of the wrong type, are out of
    acceptable range, or are in conflict with one another. in
    c:\phpweb\admin.card.view.php on line 196

    Warning: main(): PropGet() failed: Exception occurred. Source:
    ADODB.Connection Description: Arguments are of the wrong type, are out of
    acceptable range, or are in conflict with one another. in
    c:\phpweb\admin.card.view.php on line 197

    Any help would be greatly appricated!!

    Thanks


    Matthew Paterson Guest

  7. #6

    Default SQL Insert Error

    Ok I'm having a problem with a SQL insert going to a Access database...here
    is the connection code:

    // PHP db connection
    $db = 'C:\\Phpweb\\test.mdb';
    $conn = new COM('ADODB.Connection');
    $conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");
    $query = $conn->Execute($sql);

    Here is the print out of the SQL:

    INSERT INTO
    [Cards]([active],[division],[province],[filetitle],[air],[water],[sewage],[p
    ttw],[partVIII],[part46]) VALUES ('1','ob','Ontario','0 0 0
    0','1','1','1','1','1','1')

    Here is the errors:

    Warning: (null)(): Invoke() failed: Exception occurred. Source: Microsoft
    JET Database Engine Description: Syntax error in INSERT INTO statement. in
    c:\phpweb\admin.card.view.php on line 193

    Warning: (null)(): Invoke() failed: Exception occurred. Source:
    ADODB.Connection Description: Arguments are of the wrong type, are out of
    acceptable range, or are in conflict with one another. in
    c:\phpweb\admin.card.view.php on line 196

    Warning: main(): PropGet() failed: Exception occurred. Source:
    ADODB.Connection Description: Arguments are of the wrong type, are out of
    acceptable range, or are in conflict with one another. in
    c:\phpweb\admin.card.view.php on line 197

    Any help would be greatly appricated!!

    Thanks


    Matthew Paterson Guest

  8. #7

    Default Re: SQL Insert Error

    Matthew Paterson wrote:
    > Ok I'm having a problem with a SQL insert going to a Access database...here
    > is the connection code:
    >
    > // PHP db connection
    > $db = 'C:\\Phpweb\\test.mdb';
    > $conn = new COM('ADODB.Connection');
    This is going to be expensive and less than reliable.

    Do yourself a favour and use PEAR:DB
    you can change to a real RDBMS later and your code will be none the
    wiser. Here is a class I wrote as part of an MSAccess db app.

    You need only look at the constructor if you don't want to use the rest.

    Warning: the ODBC driver for PEAR:DB has a bug. It is designed to work
    with unix style odbc driver. Go to c:/php/PEAR/DB/odbc.php and change

    $conn = @$connect_function($dbhost, $user, $pw);
    to
    $conn = @$connect_function($dsninfo['database'], $user, $pw);

    on line 134

    I spoke to the maintainer of odbc.php and the fault as acknowledged but
    left alone.

    if you have no pear directory, then go the a dos command window, change
    to your php directory, and type "go-pear" (make sure you are connected
    to the net).


    <?php

    include_once "db.php";
    include_once "class_Exception.php";

    class sopsDb {

    var $strUser ="";
    var $strPass ="";
    var $strDBname = "sops";
    var $strHost = "localhost";
    var $strDbType = "odbc";
    var $dsn;
    var $db;

    function sopsDb() {
    $this->dsn =
    $this->strDbType."://"
    // .$this->strUser.":"
    // .$this->strPass."@"
    .$this->strHost."/"
    .$this->strDBname
    ;
    if (DB::isError($this->db = DB::connect($this->dsn)))
    new
    Exception($this->db->getMessage().":\n".$this->db->getUserinfo(),true);
    }

    function &query($sql,$complain=true) {
    $res =& $this->db->query($sql);
    if($complain) $this->DBerrorCheck($res,$sql);
    return $res;
    }

    function DBerrorCheck($obj,$sql) {
    if (DB::isError($obj)) {
    $err = $obj->getMessage().":\n".$obj->getUserinfo();

    if(stristr($obj->getUserinfo(),"duplicate values"))
    $err = "The name you specified already exists.";

    new Exception($err,true);
    }
    }

    function strMSEscapeSingleQuotes(&$arrPayload,$arrFields) {
    foreach($arrFields AS $field) {
    $arrPayload[$field] =
    str_replace("'","''",$arrPayload[$field]);
    }
    }

    function strOdbcDateTimeFormat($intTs=0) {
    if(!$intTs) $intTs=time();
    // { ts '1998-05-02 01:23:56.123' }
    //
    [url]http://msdn.microsoft.com/library/en-us/acdata/ac_8_con_03_04l0.asp[/url]
    $strTs = "{ts'";
    $strTs .= date("Y-m-d H:i:s",$intTs);
    $strTs .= "'}";
    return $strTs;
    }

    function MsSqlPrep(&$sql) {
    $sql = str_replace(" '',"," NULL,",stripslashes($sql));
    }

    function escapeUri($uri) {
    if(strpos($uri,"\\\\") === 0)
    $uri = "file://".str_replace("\\","/",$uri);
    return $uri;
    }

    function query2d($sql) {
    $arr2d = array();
    $objResTaskSystems = $this->query($sql);
    while($arr2d[] = $objResTaskSystems->fetchRow(DB_FETCHMODE_ASSOC));
    if(is_array($arr2d)) array_pop($arr2d);
    return $arr2d;
    }
    }

    ?>

    Terence Guest

  9. #8

    Default Re: SQL Insert Error

    Do not use VALUES (), instead use SELECT.

    [url]www.elvenbyte.es.kz[/url]

    On Wed, 19 Nov 2003 03:33:57 GMT, "Matthew Paterson"
    <mpaterso@telus.net> wrote:
    >Ok I'm having a problem with a SQL insert going to a Access database...here
    >is the connection code:
    >
    >// PHP db connection
    >$db = 'C:\\Phpweb\\test.mdb';
    >$conn = new COM('ADODB.Connection');
    >$conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");
    >$query = $conn->Execute($sql);
    >
    >Here is the print out of the SQL:
    >
    >INSERT INTO
    >[Cards]([active],[division],[province],[filetitle],[air],[water],[sewage],[p
    >ttw],[partVIII],[part46]) VALUES ('1','ob','Ontario','0 0 0
    >0','1','1','1','1','1','1')
    >
    >Here is the errors:
    >
    >Warning: (null)(): Invoke() failed: Exception occurred. Source: Microsoft
    >JET Database Engine Description: Syntax error in INSERT INTO statement. in
    >c:\phpweb\admin.card.view.php on line 193
    >
    >Warning: (null)(): Invoke() failed: Exception occurred. Source:
    >ADODB.Connection Description: Arguments are of the wrong type, are out of
    >acceptable range, or are in conflict with one another. in
    >c:\phpweb\admin.card.view.php on line 196
    >
    >Warning: main(): PropGet() failed: Exception occurred. Source:
    >ADODB.Connection Description: Arguments are of the wrong type, are out of
    >acceptable range, or are in conflict with one another. in
    >c:\phpweb\admin.card.view.php on line 197
    >
    >Any help would be greatly appricated!!
    >
    >Thanks
    >
    eLVeNBYTe
    [url]http://www.elvenbyte.es.kz[/url]
    eLVeNBYTe Guest

  10. #9

    Default Re: SQL Insert Error

    On Wed, 19 Nov 2003 03:33:57 GMT, "Matthew Paterson"
    <mpaterso@telus.net> wrote:
    >INSERT INTO
    >[Cards]([active],[division],[province],[filetitle],[air],[water],[sewage],[p
    >ttw],[partVIII],[part46]) VALUES ('1','ob','Ontario','0 0 0
    >0','1','1','1','1','1','1')
    I thought square brackets meant "value of" in Access?

    Have you tried...

    INSERT INTO Cards
    (active,division,province,filetitle,air,water,sewa ge,pttw,partVIII,part46)
    VALUES
    ('1','ob','Ontario','0 0 0 0','1','1','1','1','1','1')

    Also, are all the fields character datatypes?

    kafooey
    - [email]kafooey@nospam.yahoo.co.uk[/email]
    - [url]http://www.pluggedout.com/blog[/url]
    kafooey Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139