Could someone help me with this?

ins.CommandText = " INSERT INTO CoupleTbl (acntId, kasal, spouseName) " &
                  "SELECT (acntId, " & dtpMarriage.Value & " , '" & txtSpouseName.Text & "') FROM AccountsTbl INNER JOIN " & "CoupleTbl ON AccountsTbl.acntId = CoupleTbl.acntId);"

        ins.CommandType = CommandType.Text
        ins.Connection = con
        ins.ExecuteNonQuery()
        MsgBox("Record Inserted")

error says : Syntax error (comma) in query expression '(acntId, 5/17/2013 , 'Last , First, Middle')'

Recommended Answers

All 4 Replies

I'm not sure, but could it be the comma in between "Last" and "First" or 'theDate' and "Last"? It has a space on either side of it instead of to it's right.

error says : Syntax error (comma) in query expression '(acntId, 5/17/2013 , 'Last , First, Middle')'

'Last , First, Middle'
You want to insert 3 fields but the value of txtSpouseName.Text make compiler confused and rise an error.
compiler might thought that it should be 'Last' , 'First', 'Middle'.

its still the same even if I removed the comma on the textbox

Syntax error (comma) in query expression '(acntId, 5/17/2013 , 'Doe John Santos')'.

If I provide some values of my own I get a query that looks like

INSERT INTO CoupleTbl (acntId, kasal, spouseName) 
SELECT (acntId, Married , 'John') 
  FROM AccountsTbl INNER JOIN CoupleTbl ON AccountsTbl.acntId = CoupleTbl.acntId);

Note that there are no single quotes around Married so my suggestion is to revise your query as

ins.CommandText = " INSERT INTO CoupleTbl (acntId, kasal, spouseName) " &
"SELECT (acntId, '" & dtpMarriage.Value & "' , '" & txtSpouseName.Text & "') 
FROM AccountsTbl INNER JOIN " & "CoupleTbl ON AccountsTbl.acntId = CoupleTbl.acntId);"

Of course, I am assuming that dtpMarriage.Value contains a field value rather than a field name. You didn't say either way.

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.