I have designed a for to submit some info to a sql database, but when i enter the information to the form fields and click submit, I get an error saying that a null value cannot be submitted, when it should not be null.
Not to sound whiney, but i really need a code fix, not links to msdn pages that define properties (usually dont do this, but i have a deadline to submit this to my tech admin of my company's site)
Here is the code, and THANK YOU to anyone who helps me with this!!
<%
@.PageLanguage="VB"MasterPageFile="~/MasterPage.master" %><
scriptrunat="server">PrivateSub Submitdata(ByVal SourceAsObject,ByVal eAs EventArgs)SqlDataSource1.Insert()
EndSub' Submitdata</
script><
asp:ContentID="Content1"runat="server"ContentPlaceHolderID="ContentPlaceHolder1"><asp:sqldatasourceid="SqlDataSource1"runat="server"connectionstring="<%$ ConnectionStrings:clientInfoConnectionString %>"selectcommand="SELECT Client Name,Client Address FROM Clients"insertcommand="INSERT INTO Clients (ClientName,ClientAddress) VALUES (@.CName,@.CAddress)"><insertparameters><asp:formparametername="CName"formfield="Namebox"/><asp:formparametername="CAddress"formfield="Addressbox"/></insertparameters></asp:sqldatasource> Name:<br/><asp:TextBoxID="Namebox"runat="server"/><br/><asp:RequiredFieldValidatorID="RequiredFieldValidator1"runat="server"ControlToValidate="Namebox"ErrorMessage="Please Enter A Name"></asp:RequiredFieldValidator>
<br/>Address:<br/><asp:TextBoxID="Addressbox"runat="server"/><br/>
<asp:RequiredFieldValidatorID="RequiredFieldValidator2"runat="server"ControlToValidate="Addressbox"ErrorMessage="Please Enter An Address"></asp:RequiredFieldValidator>
<br/><asp:ButtonID="Submitbtn"runat="server"Text="Submit"OnClick="Submitdata"/><br/>
</
asp:Content>Thanks,
The King
If the columns accept null values your code without any change will work.To Insert into a column wich donot accept null this is the work around.
Make a small change in your code to make it work.
Remove the input parameter specified in the design and add the same in your code .so this part
<insertparameters>
<asp:formparametername="CName"formfield="Namebox"/>
<asp:formparametername="CAddress"formfield="Addressbox"/>
</insertparameters>
can be removed.
In the submit click add this code
SqlDataSource1.InsertParameters.Add(
"CName", Namebox.Text)SqlDataSource1.InsertParameters.Add(
"CAddress", Addressbox.Text)Now you are done.
|||All I can say is
Thank You!!!!!!
It finally works!
Thanks so much,
The King
No comments:
Post a Comment