I have a data base containing 2 columns called Name and Contact. I want to store cookies in both the columns. Heres what i did :
<asp:SqlDataSource ID="Sql1" runat="server" ConnectionString="<%$ ConnectionStrings:contacts %>" OnSelected="selected" SelectCommand="select * from contacts" InsertCommand="insert contacts (Name,Contact) values(@Name,@Contact)"><insertparameters><asp:CookieParameter Name="Contact" CookieName="Contact" /><asp:CookieParameter Name="Name" CookieName="Name" /></insertparameters>
- I have used cookie parameters in insert parameters. which means when ever the page is requested then a cookie needs to be stored in the database in both columns.
FORMVIEW: ( take input from user)
<asp:FormView ID="fv" runat="server" DefaultMode="Insert" DataSourceID="sql1"><insertitemtemplate><asp:Label ID="l1" Text="Vote for" runat="server"/><asp:RadioButtonList DataValueField='<%#Bind("Name")%>' ID="rbl" runat="server"><asp:ListItem Text="Varinder" Value="Varinder" Selected="true" /><asp:ListItem Text="Santosh" Value="Santosh" /> <asp:Button ID="b1" Text="Submit" runat="server" CommandName="Insert" /> </insertitemtemplate>
- I have used a form view for the user to input. I have just tried to implement a voting sort of a mechanism in which when a radio button is selected and a button is pressed, then a cookie will be stored against that person's entry in the database.
The code behind is :
protected void Page_Load(object sender, EventArgs e)
string identifier = Guid.NewGuid().ToString();
HttpCookie namecoockie = new HttpCookie("Name",identifier);
namecoockie.Expires = DateTime.MaxValue;
- What i wanted to do is that when ever user selects a radio button then a cookie corresponding to that radio button selection will be stored into the data base.
- I am successfull in it, but the catch is that my cookie is being duplicated in only column, where as i want the entry of the cookie in both Name and Contact column.
- My doubt is that the cookie is of type string. The "Name" column of my database is also of type string, but "Contact" column is of type int.
- Is this the reason? Because in the insert parameter i have clearly specified what to insert where.