Sunday, March 11, 2012
Another NQ: Inserting Image
Otherwise you will likely need to use a API. Google it in their groups
server and you might find what you need:
http://groups-beta.google.com/group...into+sql+server
----
Louis Davidson - drsql@.hotmail.com
SQL Server MVP
Compass Technology Management - www.compass.net
Pro SQL Server 2000 Database Design -
http://www.apress.com/book/bookDisplay.html?bID=266
Blog - http://spaces.msn.com/members/drsql/
Note: Please reply to the newsgroups only unless you are interested in
consulting services. All other replies may be ignored :)
"LacOniC" <iletisim@.bigfoot.com> wrote in message
news:exhH8ruOFHA.3808@.TK2MSFTNGP14.phx.gbl...
> How can i insert images into column easily. Can i do this by Query
> Browser?
>
ANOTHER NEWBIE QUESTION
IF INSERTING ...
IF DELETING ...
IF UPDATING ...
TIA
Allan M. Hart"Allan Hart" <allan.hart@.mnsu.edu> wrote in message news:<bqe8qk$1ch$1@.nitrogen.mnsu.edu>...
> Can someone tell me the Transact-SQl equivalent of any of these:
> IF INSERTING ...
> IF DELETING ...
> IF UPDATING ...
> TIA
> Allan M. Hart
I don't know what that syntax means, but I guess it's from trigger
code in another product, to identify the firing action? If so, then
one approach in MSSQL is to check for the existence of rows in the
inserted and deleted tables:
/* INSERT */
if exists (select * from inserted)
and not exists (select * from deleted)
/* DELETE */
if not exists (select * from inserted)
and exists (select * from deleted)
/* UPDATE */
if exists (select * from inserted)
and exists (select * from deleted)
Simon|||To add to Simon's response, you won't be able to infer the statement type
when no rows are affected by the statement firing the trigger.
/* UNKNOWN */
if not exists (select * from inserted)
and not exists (select * from deleted)
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Allan Hart" <allan.hart@.mnsu.edu> wrote in message
news:bqe8qk$1ch$1@.nitrogen.mnsu.edu...
> Can someone tell me the Transact-SQl equivalent of any of these:
> IF INSERTING ...
> IF DELETING ...
> IF UPDATING ...
> TIA
> Allan M. Hart|||Simon Hayes wrote:
> "Allan Hart" <allan.hart@.mnsu.edu> wrote in message news:<bqe8qk$1ch$1@.nitrogen.mnsu.edu>...
>>Can someone tell me the Transact-SQl equivalent of any of these:
>>
>>IF INSERTING ...
>>IF DELETING ...
>>IF UPDATING ...
>>
>>TIA
>>Allan M. Hart
>
> I don't know what that syntax means, but I guess it's from trigger
> code in another product, to identify the firing action? If so, then
> one approach in MSSQL is to check for the existence of rows in the
> inserted and deleted tables:
> Simon
It is likely from Oracle and it is based upon the abilty to write a
single trigger that contains within itself the ability to detect if the
the triggering actions as an insert, update, or delete.
--
Daniel Morgan
http://www.outreach.washington.edu/...oad/oad_crs.asp
http://www.outreach.washington.edu/...aoa/aoa_crs.asp
damorgan@.x.washington.edu
(replace 'x' with a 'u' to reply)
Saturday, February 25, 2012
Annoying, cant insert into DB for some reason, even using a stored procedure.
First is the code for the insert
Sub AddCollector(Sender As Object, E As EventArgs)
Message.InnerHtml = ""If (Page.IsValid)
Dim ConnectionString As String = "server='(local)'; trusted_connection=true; database='MyCollection'"
Dim myConnection As New SqlConnection(ConnectionString)
Dim myCommand As SqlCommand
Dim InsertCmd As String = "insert into Collectors (CollectorID, Name, EmailAddress, Password, Information) values (@.CollectorID, @.Name, @.Email, @.Password, @.Information)"myCommand = New SqlCommand(InsertCmd, myConnection)
myCommand.Connection.Open()
myCommand.Parameters.Add(New SqlParameter("@.CollectorID", SqlDbType.NVarChar, 50))
myCommand.Parameters("@.CollectorID").Value = CollectorID.TextmyCommand.Parameters.Add(New SqlParameter("@.Name", SqlDbType.NVarChar, 50))
myCommand.Parameters("@.Name").Value = Name.TextmyCommand.Parameters.Add(New SqlParameter("@.Email", SqlDbType.NVarChar, 50))
myCommand.Parameters("@.Email").Value = EmailAddress.TextmyCommand.Parameters.Add(New SqlParameter("@.Password", SqlDbType.NVarChar, 50))
myCommand.Parameters("@.Password").Value = Password.TextmyCommand.Parameters.Add(New SqlParameter("@.Information", SqlDbType.NVarChar, 3000))
myCommand.Parameters("@.Information").Value = Information.TextTry
myCommand.ExecuteNonQuery()
Message.InnerHtml = "Record Added<br>"
Catch Exp As SQLException
If Exp.Number = 2627
Message.InnerHtml = "ERROR: A record already exists with the same primary key"
Else
Message.InnerHtml = "ERROR: Could not add record"
End If
Message.Style("color") = "red"
End TrymyCommand.Connection.Close()
End If
End Sub
No matter what I get a "Could not add record" message
Even substituting the insert command string with my stored procedure I would get the same thing
Stored Procedure:
CREATE Procedure CollectorAdd
(
@.Name nvarchar(50),
@.Email nvarchar(50),
@.Password nvarchar(50),
@.Information nvarchar(3000),
@.CustomerID int OUTPUT
)
ASINSERT Collectors
(
Name,
EMailAddress,
Password,
Information
)VALUES
(
@.Name,
@.Email,
@.Password,
@.Information
)
GO
Can anyone see any problems with this code? It looks good to me but I get the same message always.
ThanksWhy not print out the actual exception text (exp.ToString(), for instance)? Then the exception will tell you why.|||Wow, nice little trick. It helped me find the problem. I had an expected parameter in the SP that I was not supplying.
Thank You