Print Page | Close Window

Add records to dataset (SQL) problem

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Database Discussion
Forum Description: Discussion and chat on database related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=9671
Printed Date: 28 March 2026 at 2:25am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Add records to dataset (SQL) problem
Posted By: pmkosana
Subject: Add records to dataset (SQL) problem
Date 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




 



-------------
ALWAYZ SHINE ALONG THE WAY



Replies:
Posted By: Semikolon
Date Posted: 09 February 2004 at 3:38pm
do you get any errors or something?


Posted By: michael
Date 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 ......



-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: pmormr
Date Posted: 09 February 2004 at 7:23pm
darn is that spaced out...

-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: pmkosana
Date 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



-------------
ALWAYZ SHINE ALONG THE WAY



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net