Web Wiz - Solar Powered Eco Web Hosting

  New Posts New Posts RSS Feed - Add records to dataset (SQL)  problem
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Add records to dataset (SQL) problem

 Post Reply Post Reply
Author
pmkosana View Drop Down
Newbie
Newbie
Avatar

Joined: 09 February 2004
Location: Germany
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmkosana Quote  Post ReplyReply Direct Link To This Post Topic: Add records to dataset (SQL) problem
    Posted: 09 February 2004 at 3:01pm

hello guyz

I have a problem of adding new records in my dataset,the code is working,but i don#t know why i cannot add,is it possible that this could have something to do with allowing adding record to sql_permission ,i tried to justify everything ,I stil cannot get it

there is my code

<code>

sub page_load(sender as object,E as EventArgs)


 


  myconnection = new sqlconnection("server= G103-TT03;database=CampusLANDB;Trusted_Connection=true")


  If Not (IsPostBack)


   DataBind()


   end if


  


   end sub


  


   Sub addNics_Click(sender as object,E as EventArgs)


  


   Dim Ds as dataSet


   Dim mycommand as sqlcommand


 


  


 





   if au_MAC_Address.value = "" or au_Name.value="" or au_Actiontext.value="(NONE)" or au_ExpirationDate.value=""


  


   Message.InnerHtml="Error:Null Values not Allowed for Nic_Name ,MAC_Address "


   Message.style("color")="red"


   DataBind()


   end if


  


   Dim InsertCmd As string ="Insert Into tNics (au_FK_Students,au_Name,au_MAC_Address,au_actiontext)values( @FK_Students,@Name,@MAC_Address,@actiontext)"


  


   mycommand =new sqlcommand (insertCmd , myconnection)


  


   mycommand.parameters.add(new sqlparameter("@FK_Students", sqlDBType.Int, 4))


   mycommand.parameters("@FK_Students").value = server.htmlencode(au_FK_Students.value)


  


   mycommand.parameters.add(new sqlparameter("@Name", sqlDBtype.NVarChar,50))


   mycommand.parameters("@Name").value=server.htmlEncode(au_Nam e.value)


  


   mycommand.parameters.add(new sqlparameter("@MAC_Address",SqlDBType.NvarChar,12))


   mycommand.parameters("@MAC_Address").Value=server.htmlEncode (au_MAC_Address.Value)


  


   mycommand.parameters.add(new sqlparameter("@actiontext",sqlDBType.NvarChar,20))


   mycommand.parameters("@actiontext").value= server.HtmlEncode(au_actiontext.value)


  


   mycommand.parameters.add(new sqlparameter("@expirationdate", sqldbType.NvarChar,20))


   mycommand.parameters("@expirationdate").value = server.htmlEncode(au_expirationdate.value)


  


   mycommand.connection.open()


  


   try


   mycommand.ExecuteNonQuery()


   Message.InnerHtml=" record Added<br>"& InsertCmd.ToString()


  


   Catch Exp as SQLException


  


   if Exp.Number=2627


  


   Message.Innerhtml="Error:A record Already exist With the same Identity"


   else


   Message.Innerhtml="Error could not add record,please insure that there are no null values"


  


   end if


  


   Message.Style("color")="red"


   


   End try


  


   mycommand.connection.close()


  


   dataBind()


   end sub


  


   sub  dataBind()


  


   dim mycommand as sqlDataAdapter= new sqldataAdapter("select id_students,Name,EventDate,actiontext,ID_Action,mac_address, expirationdate from tNics,tAction,tStudents,tHistory Where tstudents.iD_Students=tNics.FK_Students and tHistory.FK_Action=tAction.ID_Action and tstudents.login1='pmkosana'", myconnection)


  


   dim DS as dataset= new dataset()


   mycommand.fill(DS,"tNics,tStudents,tAction,tHistory")


  


   mydatagrid.dataSource=DS.tables("tNics,tStudents,tAction,tHi story").DefaultView


   Mydatagrid.dataBind()


   end sub

<code>

 

thannk in advance

pmkosana




 

Back to Top
Semikolon View Drop Down
Senior Member
Senior Member


Joined: 09 September 2003
Location: Norway
Status: Offline
Points: 1718
Post Options Post Options   Thanks (0) Thanks(0)   Quote Semikolon Quote  Post ReplyReply Direct Link To This Post Posted: 09 February 2004 at 3:38pm
do you get any errors or something?
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4671
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 09 February 2004 at 6:47pm

When posting code do you mind formatting it a little better? It's a b to read.

Do you have an edititem template? Plus I don't see any click handler for the Datagrid Insert Command ......

Back to Top
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post Posted: 09 February 2004 at 7:23pm
darn is that spaced out...
Back to Top
pmkosana View Drop Down
Newbie
Newbie
Avatar

Joined: 09 February 2004
Location: Germany
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmkosana Quote  Post ReplyReply Direct Link To This Post Posted: 10 February 2004 at 5:37am

hell no man ,it's not spaced out

I"m sorry guyz for my unintellectual formatting

I have an (asp:datagrid) and onserverclick cmd button in the form m , and I don"t get any errors,was I suppose to specify any action in script?

 

thanks in advance

pm81

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.07
Copyright ©2001-2024 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Policy

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2024 Web Wiz Ltd. All rights reserved.