Click here to Skip to main content
15,902,787 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi all,

i m making a simple registration form of the student.
for this i writ a stored procedure named as"sp_stuDetails" whose code is as follows


SQL
USE [C:\DOCUMENTS AND SETTINGS\HP-ZEZ\MY DOCUMENTS\VISUAL STUDIO 2008\PROJECTS\GETSETGO_CCE\GETSETGO_CCE\CCE.MDF]
GO



CREATE proc [dbo].[sp_stuDetails]
@strSRNo varchar(25),
@datAdmission datetime,
@strName varchar(50),
@strGender varchar(1),
@datBirth datetime,
@strFather varchar(50),
@strMother varchar(50),
@strGaurdian varchar(200),
@strAddress varchar(200),
@strPermanenetAddress varchar(200),
@strContactDetails varchar(200),
@strMobile1 varchar(25),
@strMobile2 varchar(25),
@intCityID int,
@intStateID int,
@intDistrictID int,
@intReturn int=0 output
as
begin
declare @intNextID int

begin transaction
 select @intNextID = isnull(max(intStudentID),0)+1 from tblStudent1;
 insert into tblStudent1 (
intStudentID,
strSRNo,
datAdmission,
strName,
strGender,
datBirth,
strFather,
strMother,
strGaurdian,
strAddress,
strPermanenetAddress,
strContactDetails,
strMobile1,
strMobile2,
intCityID,
intStateID,
intDistrictID
)
values(
@intNextID,
@strSRNo,
@datAdmission,
@strName,
@strGender,
@datBirth,
@strFather,
@strMother,
@strGaurdian,
@strAddress,
@strPermanenetAddress,
@strContactDetails,
@strMobile1,
@strMobile2,
@intCityID,
@intStateID,
@intDistrictID
)
if @@error <> 0
    begin
        rollback transaction
        return @intReturn
    end
    commit transaction
    set @intReturn = @intNextID
    return @intReturn
end


GO


and in .cs file Save button click event i write the code which is as follows...
C#
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["cbsegrade"].ToString());
       

            SqlCommand cmd = new SqlCommand("sp_stuDetails", con);
            cmd.CommandType = CommandType.StoredProcedure;
            con.Open();
            cmd.Parameters.AddWithValue("@strSRNo", txtSRNo.Text);
            cmd.Parameters.AddWithValue("@datAdmission", txtdatAdmission);
            cmd.Parameters.AddWithValue("@strName", txtStudentName);
            cmd.Parameters.AddWithValue("@strGender", ddlGender.SelectedValue);
            cmd.Parameters.AddWithValue("@datBirth", txtDob);
            cmd.Parameters.AddWithValue("@strFather", txtFatherName.Text);
            cmd.Parameters.AddWithValue("@strMother", txtMotherName.Text);
            cmd.Parameters.AddWithValue("@strGaurdian", txtGaurdian.Text);
            cmd.Parameters.AddWithValue("@strAddress", txtCurAdd.Text);
            cmd.Parameters.AddWithValue("@strPermanenetAddress", txtPerAdd.Text);
            cmd.Parameters.AddWithValue("@strContactDetails", txtConDetails.Text);
            cmd.Parameters.AddWithValue("@strMobile1", txtMob1.Text);
            cmd.Parameters.AddWithValue("@strMobile2", txtMob2.Text);
            cmd.Parameters.AddWithValue("@intCityID", ddlCity.SelectedValue);
            cmd.Parameters.AddWithValue("@intStateID", ddlState.SelectedValue);
            cmd.Parameters.AddWithValue("@intDistrictID", ddlDistrict.SelectedValue);
            cmd.ExecuteNonQuery();
            con.Close();



but when i run the web form
it gives the following error


No mapping exists from object type System.Web.UI.WebControls.TextBox to a known managed provider native type.


plz help me out.

thanks and regard
subiya
Posted
Updated 31-May-11 19:42pm
v2
Comments
Sunasara Imdadhusen 1-Jun-11 1:42am    
added PRE tag

I have added .Text property of txtDob
MIDL
cmd.Parameters.AddWithValue("@datBirth", txtDob.Text);
 
Share this answer
 
Comments
Kiran Sonawane 1-Jun-11 1:48am    
my 5+
ahsan.subiya 1-Jun-11 1:56am    
tnx sir .its works
This line could be the problem - cmd.Parameters.AddWithValue("@datAdmission", txtdatAdmission);
Make sure you pass a valid datetime format in this field.
 
Share this answer
 
Comments
ahsan.subiya 1-Jun-11 1:56am    
thank u sir
ahsan.subiya 1-Jun-11 2:01am    
bt now ther is another problem it gives yhe following error
Error converting data type nvarchar to int.
Abhinav S 1-Jun-11 2:03am    
@intCityID int,
@intStateID int,
@intDistrictID int,

These are int types - so you must assign int values to these parameters and not direct text box values.
ahsan.subiya 1-Jun-11 2:08am    
tnx sir error is remove now
Need to add for below as well as Sunsara suggested

MIDL
cmd.Parameters.AddWithValue("@datAdmission", txtdatAdmission);
           cmd.Parameters.AddWithValue("@strName", txtStudentName);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900