Newbie Help
-
All - I am trying to create a simple app that will capture emails and when my users try to remove their email from the db they get an error. Here is my ASP code: <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/mail.mdb" DeleteCommand="DELETE FROM [Email] WHERE (([Email] = ?) OR ([Email] IS NULL AND ? IS NULL))" InsertCommand="INSERT INTO [Email] ([Email]) VALUES (?)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT [Email] FROM [Email]"> <DeleteParameters> <asp:ControlParameter ControlID="txtEmail" Name="original_Email" PropertyName="Text" Type="String" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="Email" Type="String" /> </InsertParameters> </asp:AccessDataSource> Here is the code below: protected void btnSubscribe_Click(object sender, EventArgs e) { AccessDataSource1.InsertParameters["Email"].DefaultValue = txtEmail.Text; try { AccessDataSource1.Insert(); txtEmail.Text = ""; lblError.Text = "Email sucessfully added"; } catch { lblError.Text = "Email already exists"; } } protected void btnUnSub_Click(object sender, EventArgs e) { AccessDataSource1.DeleteParameters["Email"].DefaultValue = txtEmail.Text; try { AccessDataSource1.Delete(); txtEmail.Text = ""; lblError.Text = "Email has been removed"; } catch { lblError.Text = "Email doesn't exist"; } } Thanks for all your help
-
All - I am trying to create a simple app that will capture emails and when my users try to remove their email from the db they get an error. Here is my ASP code: <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/mail.mdb" DeleteCommand="DELETE FROM [Email] WHERE (([Email] = ?) OR ([Email] IS NULL AND ? IS NULL))" InsertCommand="INSERT INTO [Email] ([Email]) VALUES (?)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT [Email] FROM [Email]"> <DeleteParameters> <asp:ControlParameter ControlID="txtEmail" Name="original_Email" PropertyName="Text" Type="String" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="Email" Type="String" /> </InsertParameters> </asp:AccessDataSource> Here is the code below: protected void btnSubscribe_Click(object sender, EventArgs e) { AccessDataSource1.InsertParameters["Email"].DefaultValue = txtEmail.Text; try { AccessDataSource1.Insert(); txtEmail.Text = ""; lblError.Text = "Email sucessfully added"; } catch { lblError.Text = "Email already exists"; } } protected void btnUnSub_Click(object sender, EventArgs e) { AccessDataSource1.DeleteParameters["Email"].DefaultValue = txtEmail.Text; try { AccessDataSource1.Delete(); txtEmail.Text = ""; lblError.Text = "Email has been removed"; } catch { lblError.Text = "Email doesn't exist"; } } Thanks for all your help
When you post in CodepProject use the Pre tags, there is a Tool bar for you. This will make us keen to help you. Formating in important. Your Delete is not Correct
DELETE FROM [Email] WHERE (([Email] = ?) OR ([Email] IS NULL AND ? IS NULL))
the Syntax Supposed to be
DELETE TABLENAME WHERE [Email] = ? OR [Email] IS NULL
Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/
-
When you post in CodepProject use the Pre tags, there is a Tool bar for you. This will make us keen to help you. Formating in important. Your Delete is not Correct
DELETE FROM [Email] WHERE (([Email] = ?) OR ([Email] IS NULL AND ? IS NULL))
the Syntax Supposed to be
DELETE TABLENAME WHERE [Email] = ? OR [Email] IS NULL
Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/
Thanks for the Help! sk
-
Thanks for the Help! sk
Welcome :)
Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/