i know i am asking very stupid question but i really want to know what is the data type for email and phone no.for email i taked nvarchar and ph.no big int but when i click on create button @is not defined error getting so pls help me.
some times phone numbers have + or - signs or bracket signs: ( )
etc
Also integer is a limited type.
For both these, you should use varchar, its best and efficient
What error you are getting?
there must be some parameter issue, there is no harm using the parameters you are using. please post your code so we can help you in much better ways
Ashutosh Pathak
Blog: http://catchcode.blogspot.com Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
i am creating a new user in that fullname(nvarchar),username(nvarchar),email(nvarchar),phoneno(varbinary),regionID(int),stateId(int),CityID(int),security ques and ans(nvarchar).
now when i click on create button foll.error is displayed.
Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query.
Again, why are you converting email to integer? email isn't numeric. Make sure you specify varchar throughout your program and database for those two fields.
apurva16
Member
21 Points
87 Posts
Data type for email and phone no.
Apr 03, 2012 11:48 AM|LINK
hello all,
i know i am asking very stupid question but i really want to know what is the data type for email and phone no.for email i taked nvarchar and ph.no big int but when i click on create button @is not defined error getting so pls help me.
thanx.
bbcompent1
All-Star
32996 Points
8510 Posts
Moderator
Re: Data type for email and phone no.
Apr 03, 2012 11:49 AM|LINK
Try nvarchar. Can you post your code so we can see what your doing?
usman400
Contributor
3503 Points
721 Posts
Re: Data type for email and phone no.
Apr 03, 2012 11:51 AM|LINK
some times phone numbers have + or - signs or bracket signs: ( )
etc
Also integer is a limited type.
For both these, you should use varchar, its best and efficient
What error you are getting?
Ashutosh Pat...
Contributor
5737 Points
1105 Posts
Re: Data type for email and phone no.
Apr 03, 2012 11:52 AM|LINK
there must be some parameter issue, there is no harm using the parameters you are using. please post your code so we can help you in much better ways
Blog: http://catchcode.blogspot.com
Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
apurva16
Member
21 Points
87 Posts
Re: Data type for email and phone no.
Apr 03, 2012 11:58 AM|LINK
hello,
i am creating a new user in that fullname(nvarchar),username(nvarchar),email(nvarchar),phoneno(varbinary),regionID(int),stateId(int),CityID(int),security ques and ans(nvarchar).
now when i click on create button foll.error is displayed.
Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query.
and my code is..
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Usercreation.aspx.cs" Inherits="Usercreation" Title="Untitled Page" EnableEventValidation="False" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> <style type="text/css"> .style10 { font-family: Verdana; font-size: large; font-weight: bold; } .style11 { font-family: Verdana; font-size: large; font-weight: bold; height: 34px; } .style12 { height: 34px; } </style> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server"> <body> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> </div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <br /> <table> <tr> <td class="style10">FullName: </td> <td> <asp:TextBox ID="txtFullname" runat="server"></asp:TextBox> </td> <tr> <td class="style11">UserName: </td> <td class="style12"> <asp:TextBox ID="txtUserName" runat="server" ontextchanged="txtUserName_TextChanged" AutoPostBack="True" ></asp:TextBox> </td> <td class="style12"><asp:Image ID="imgUser" runat="server" Visible="false" /></td> <td class="style12"><asp:Label ID="lblUser" runat="server"></asp:Label></td> </tr> <tr> <td class="style10">Password: </td> <td> <asp:TextBox ID="txtPassword" runat="server" TextMode=Password></asp:TextBox> <tr> <td class="style10">ConfirmPassword: </td> <td> <asp:TextBox ID="txtConfirmpassword" runat="server" TextMode=Password></asp:TextBox> <tr> <td class="style10">Email ID: </td> <td> <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox> </td> </tr> <tr> <td class="style10">PhoneNo.: </td> <td> <asp:TextBox ID="txtPhoneno" runat="server" MaxLength=10></asp:TextBox> <tr> <td class="style10">Region: </td> <td> <asp:DropDownList ID="DdlRegion" runat="server" onselectedindexchanged="DdlRegion_SelectedIndexChanged" AutoPostBack="True"> </asp:DropDownList> <tr> <td class="style10">State: </td> <td> <asp:DropDownList ID="DdlState" runat="server" onselectedindexchanged="DdlState_SelectedIndexChanged" AutoPostBack="True" style="height: 22px"> </asp:DropDownList> <tr> <td class="style10">City: </td> <td> <asp:DropDownList ID="DdlCity" runat="server" AutoPostBack="True"> </asp:DropDownList> <tr> <td class="style10">Security Question: </td> <td> <asp:TextBox ID="txtSecurityquestion" runat="server" AutoPostBack="True" ></asp:TextBox> <tr> <td class="style10">Security Answer: </td> <td> <asp:TextBox ID="txtSecurityanswer" runat="server"></asp:TextBox> </tr> </table> </ContentTemplate> </asp:UpdatePanel> <asp:Button ID="btnCreate" runat="server" Text="Create" onclick="btnCreate_Click" /> </form> </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> </asp:Content>hope u understand my problem.
thanx.
apurva16
Member
21 Points
87 Posts
Re: Data type for email and phone no.
Apr 03, 2012 12:02 PM|LINK
cs code is..
Public partial class Usercreation : System.Web.UI.Page { DataSet DS = new DataSet(); private String strConnection = "Data Source=ABHI\\SQLEXPRESS;Initial Catalog=Live proj;Integrated Security=True"; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SqlConnection con = new SqlConnection(strConnection); SqlCommand Cmd = new SqlCommand("Select * From Region", con); SqlDataAdapter DA = new SqlDataAdapter(Cmd); DA.Fill(DS, "Region"); DdlRegion.DataSource = DS.Tables["Region"]; DdlRegion.DataTextField = "RegionName"; DdlRegion.DataValueField = "RegionID"; DdlRegion.DataBind(); DdlRegion.Items.Insert(0, "---Select---"); } } SqlCommand cmd; //SqlConnection conn = new SqlConnection("Data Source=ABHI\\SQLEXPRESS;Initial Catalog=Live proj;Integrated Security=True"); protected void txtUserName_TextChanged(object sender, EventArgs e) { if (txtUserName.Text != string.Empty) { SqlConnection con = new SqlConnection(strConnection); cmd = new SqlCommand("select count(*) from Newuser where UserName= @UserName", con); SqlParameter username = new SqlParameter("@UserName", SqlDbType.VarChar); username.Value = txtUserName.Text.Trim().ToString(); cmd.Parameters.Add(username); con.Open(); int result = (Int32)cmd.ExecuteScalar(); con.Close(); if (result >= 1) { imgUser.ImageUrl = "unavailable.png"; imgUser.Visible = true; lblUser.Text = "not available"; lblUser.ForeColor = System.Drawing.Color.Red; } else { imgUser.ImageUrl = "tick.png"; imgUser.Visible = true; lblUser.Text = "Available"; lblUser.ForeColor = System.Drawing.Color.Green; } } } protected void btnCreate_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(strConnection); con.Open(); cmd = new SqlCommand("Insert Into Newuser VALUES('" +txtFullname.Text+ "','" +txtUserName.Text+ "','"+txtPassword.Text+"','"+txtConfirmpassword.Text+"','"+txtEmail.Text+"','"+txtPhoneno.Text+"','"+DdlRegion.SelectedValue+"', '"+DdlState.SelectedValue+"','"+DdlCity.SelectedValue+"','"+txtSecurityquestion.Text+"','"+txtSecurityanswer.Text+"')", con); cmd.ExecuteNonQuery(); } protected void DdlRegion_SelectedIndexChanged(object sender, EventArgs e) { if (DdlRegion.SelectedValue != "Select") { SqlConnection con = new SqlConnection(strConnection); SqlCommand Cmd1 = new SqlCommand("Select * From State Where RegionID=" + DdlRegion.SelectedValue + "", con); SqlDataAdapter DA1 = new SqlDataAdapter(Cmd1); DA1.Fill(DS, "State"); DdlState.DataSource = DS.Tables["State"]; DdlState.DataTextField = "StateName"; DdlState.DataValueField = "StateID"; DdlState.DataBind(); DdlState.Items.Insert(0, "----Select----"); } } protected void DdlState_SelectedIndexChanged(object sender, EventArgs e) { if (DdlState.SelectedValue != "Select") { SqlConnection con = new SqlConnection(strConnection); SqlCommand Cmd1 = new SqlCommand("Select * From City Where stateid=" + DdlState.SelectedValue + "", con); SqlDataAdapter DA1 = new SqlDataAdapter(Cmd1); DA1.Fill(DS, "City"); DdlCity.DataSource = DS.Tables["City"]; DdlCity.DataTextField = "CityName"; DdlCity.DataValueField = "CityID"; DdlCity.DataBind(); DdlCity.Items.Insert(0, "----Select----"); } } protected void DdlCity_SelectedIndexChanged(object sender, EventArgs e) { } }bbcompent1
All-Star
32996 Points
8510 Posts
Moderator
Re: Data type for email and phone no.
Apr 03, 2012 12:02 PM|LINK
Phoneno should be varchar, not varbinary.
bbcompent1
All-Star
32996 Points
8510 Posts
Moderator
Re: Data type for email and phone no.
Apr 03, 2012 12:02 PM|LINK
Change your database field from varbinary to varchar.
apurva16
Member
21 Points
87 Posts
Re: Data type for email and phone no.
Apr 03, 2012 12:06 PM|LINK
ya changed now when i clik on button ,
Conversion failed when converting the varchar value 'apu@yahoo.com' to data type int.
error displayed.
thnx for helping.
bbcompent1
All-Star
32996 Points
8510 Posts
Moderator
Re: Data type for email and phone no.
Apr 03, 2012 12:12 PM|LINK
Again, why are you converting email to integer? email isn't numeric. Make sure you specify varchar throughout your program and database for those two fields.