Please help a newbie: My first SQL Database insert

Results 1 to 4 of 4

Thread: Please help a newbie: My first SQL Database insert

  1. #1
    Join Date
    Dec 1969

    Default Please help a newbie: My first SQL Database insert

    Help im going nuts!<BR><BR>I&#039m trying to take data that the user enters into an ASP page and enter<BR>it into my SQL server database.<BR>The names of my variables on the ASP page are: strTitle, StrDescription,<BR>strPicture, StrStartPrice, strDuration, StrUsername, and strEmail.<BR><BR>My database on MS SQL Server is named eBild, the name of the table is<BR>AuctionItem and the names of my fields in the table are ItemNum, Title,<BR>Description, Category, SellerEmail, PlacedDateTime, StartBid,<BR>BuyerEmail, CurrentBid, and ExpireDateTime (Some of the fields will be<BR>left blank)<BR><BR>The book im using uses an Access database so it uses a different driver<BR>(no help to me).<BR><BR>Can someone tell me the syntax for adding the variables listed up top<BR>into the table fields listed after that?<BR><BR>I&#039ve been trying for 2 days and I&#039m getting nowhere.<BR>Thanks!<BR>Marc

  2. #2
    ksymeon Guest

    Default RE: Please help a newbie: My first SQL Database in

    Hey! Seems you are into trouble! First of all I assume that the fields which will be left blank, have the NULL attribute in your Table design (I guess you checked that! If not then go to SQL Enterprise Manager, edit your Table and set the required fields to null!)<BR><BR>Syntax of INSERT is:<BR><BR>INSERT INTO mytable (f_one,f_two,...) VALUES (v_one,v_two)<BR><BR>Now in ASP<BR><BR>SQLStr = "INSERT INTO AuctionItem (Title,Description) VALUES (&#039" &_<BR>& strTitle & "&#039,&#039" &_<BR>& strDescription & "&#039"<BR>Conn.Execute (strDescription)<BR><BR>Try to insert one field at a time.<BR><BR>Kostas Symeonidis<BR>check ""!

  3. #3
    Join Date
    Dec 1969

    Default Thanks- Im SO CLOSE but...

    Thanks VERY MUCH for the help, because of you Im a lot closer now but still getting errors.<BR>Can you or someone tell me what im missing?<BR>I took out the uid,<BR>password, and server just to show you all...thanks!:<BR><BR>&#060;%<BR> Dim objConn, strConn<BR><BR> set objConn = Server.CreateObject("ADODB.Connection")<BR> strconn = "DRIVER={SQL<BR>Server};uid=xxxx;password=xxxx;Ser ver=xxxxx;Database=Ebild"<BR> Conn.addnew<BR><BR> connection.execute "INSERT INTO auctionitem<BR><BR>(Title,Description,Category,Sel leremail,PlacedDateTime,StartBid,BuyerEmail,Curren tBid,ExpireDateTime,<BR>picture)"<BR> VALUES<BR><BR>(Title,Description,Category,Sellerem ail,PlacedDateTime,StartBid,BuyerEmail,CurrentBid, ExpireDateTime,<BR>picture)"<BR><BR>SQLStr = "INSERT INTO AuctionItem (Title,Description, category, selleremail,<BR>placeddatetime, startBid, BuyerEmail, CurrentBid, ) VALUES (&#039" &_<BR>& strTitle & "&#039,&#039" &_<BR>& strDescription & "&#039,&#039" &_<BR>& strCategory & "&#039,&#039" &_<BR>& strSelleremail & "&#039,&#039" &_<BR>& strPlacedDateTime & "&#039,&#039" &_<BR>& strStartBid & "&#039,&#039" &_<BR>& strBuyerEmail & "&#039,&#039" &_<BR>& strCurrentBid & "&#039,&#039" &_<BR>& strExpireDateTime & "&#039,&#039" &_<BR>& strPicture & "&#039"<BR>Conn.Execute (strDescription)<BR>%&#062;<BR><BR>

  4. #4
    Trung Dang Guest

    Default RE: Thanks- Im SO CLOSE but...

    From your code, I can see that you never did open your connection to the database...<BR>You need:<BR>objConn.Open strConn after your strConn definition<BR><BR>Get rid of:<BR>1) Conn.addnew statement<BR>2) Connection.Execute statement<BR><BR>Change your "Conn.Execute" to "objConn.Execute SQLStr"<BR><BR>Good luck!<BR>

Posting Permissions

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