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