You said only one character is being .... That is why I said to change datatype of stored procedure parameters from varchar to varchar(50) or some integer(What is happening is your procedure is being passed correct full values but while execution the parameters
inside SP hold only one character because you are assigning these to the procedure parameters having datatype just varchar which can store only one character ). Also, your if has no else written before update statement.. Just make this changes and tell if
you still face problems
harika26
Member
87 Points
141 Posts
no error in code but still not getting values
May 16, 2012 07:14 AM|LINK
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data;
using
System.Data.SqlClient;
using
System.Configuration;
public
partial class ADDFORM : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Page.Session["StudentId"]!= null)
{
txtid.Text = Page.Session[
"StudentID"].ToString();
txtname.Text = Page.Session[
"StudentName"].ToString();
txtAdd1.Text = Page.Session[
"StudentAddress1"].ToString();
txtAdd2.Text = Page.Session[
"StudentAddress2"].ToString();
txtAdd3.Text = Page.Session[
"StudentAddress3"].ToString();
txtPin.Text = Page.Session[
"pincode"].ToString();
txtPhon.Text = Page.Session[
"phonenumber"].ToString();
txtEmaild.Text = Page.Session[
"EmailId"].ToString();
txtCourse.Text = Page.Session[
"Course"].ToString();
txtDateofbirth.Text = Page.Session[
"DateofBirth"].ToString();
txtjoindate.Text = Page.Session[
"CourseJoinDate"].ToString();
}
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
//Sqlconnection cn = new Sqlconnection(System.Configuration.ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
cn.Open();
SqlCommand cmd = new SqlCommand("spinsertupdate",cn);
cmd.CommandType =
CommandType.StoredProcedure;
try
{
cmd.Parameters.AddWithValue(
"@StudentID", txtid.Text.Trim());
cmd.Parameters.AddWithValue(
"@StudentName", txtname.Text.Trim());
cmd.Parameters.AddWithValue(
"@studentAddress1", txtAdd1.Text.Trim());
cmd.Parameters.AddWithValue(
"@studentAddress2", txtAdd2.Text.Trim());
cmd.Parameters.AddWithValue(
"@studentAddress3", txtAdd3.Text.Trim());
cmd.Parameters.AddWithValue(
"@pincode", txtPin.Text.Trim());
cmd.Parameters.AddWithValue(
"@tphonenumber", txtPhon.Text.Trim());
cmd.Parameters.AddWithValue(
"@EmailId",txtEmaild.Text.Trim());
cmd.Parameters.AddWithValue(
"@Course",txtCourse.Text.Trim());
cmd.Parameters.AddWithValue(
"@DateofBirth",txtDateofbirth.Text.Trim());
cmd.Parameters.AddWithValue(
"@CoursejoinDate",txtjoindate.Text.Trim());
//int StudentID=0;
//if (Page.Session["StudentId"] != null)
// StudentID = Convert.ToInt32(Page.Session["StudentId"]);
// cmd.Parameters.AddWithValue("@studentid",StudentID);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
finally
{
cn.Close ();
cmd.Dispose();
}
Response.Redirect(
"STUDENTGRID1.aspx");
}
protected void txtid_TextChanged(object sender, EventArgs e)
{
}
}
i am using the above code to insert update data but only the first letter is beibg retrieving whats the prob is the prob with code or any other prob
ignatandrei
All-Star
135148 Points
21679 Posts
Moderator
MVP
Re: no error in code but still not getting values
May 16, 2012 09:01 AM|LINK
seems ok
Start Sql Server profiler and see what values
spinsertupdate
receive.
Ravi Kumar K...
Member
727 Points
155 Posts
Re: no error in code but still not getting values
May 16, 2012 09:05 AM|LINK
can you show the procedure "spinsertupdate"
P_IT
Participant
882 Points
222 Posts
Re: no error in code but still not getting values
May 16, 2012 09:23 AM|LINK
Hi Can you paste your store procedure here?
P_IT
harika26
Member
87 Points
141 Posts
Re: no error in code but still not getting values
May 16, 2012 09:26 AM|LINK
USE [pratap] GO /****** Object: StoredProcedure [dbo].[spinsertupdate] Script Date: 05/16/2012 13:34:47 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER procedure [dbo].[spinsertupdate]( @studentid varchar, @studentName varchar, @studentAddress1 varchar, @studentAddress2 varchar, @studentAddress3 varchar, @pincode varchar, @tphonenumber varchar, @EmailId varchar, @Course varchar, @DateofBirth varchar, @CoursejoinDate varchar ) as Begin if(@studentID=null) insert into prathap( StudentId, StudentName, StudentAddress1, StudentAddress2, StudentAddress3, pincode, phonenumber, EmailId, Course, DateofBirth, CourseJoinDate ) values( @studentid, @studentName, @studentAddress1, @studentAddress2, @studentAddress3, @pincode, @tphonenumber, @EmailId, @Course, @DateofBirth, @CoursejoinDate ) end update prathap set studentName=@studentName, studentAddress1=@studentAddress1, studentAddress2=@studentAddress2, studentAddress3=@studentAddress3, pincode=@pincode, phonenumber=@tphonenumber, EmailId=@EmailId, Course=@Course, DateofBirth=@DateofBirth, CoursejoinDate=@CoursejoinDate where StudentId=@studentid
i am using this sp for the above one
Ravi Kumar K...
Member
727 Points
155 Posts
Re: no error in code but still not getting values
May 16, 2012 09:30 AM|LINK
In the stored procedure, the paramaters datatype is just varchar(which means only 1 .. not sure), change it to varchar(50) or some number
Use the following syntx in stored procedure
if(..)
Begin
...
End
else
begin
..
end
harika26
Member
87 Points
141 Posts
Re: no error in code but still not getting values
May 16, 2012 09:34 AM|LINK
spinsertupdate is taking the values whihc i am writing
Ravi Kumar K...
Member
727 Points
155 Posts
Re: no error in code but still not getting values
May 16, 2012 09:45 AM|LINK
You said only one character is being .... That is why I said to change datatype of stored procedure parameters from varchar to varchar(50) or some integer(What is happening is your procedure is being passed correct full values but while execution the parameters inside SP hold only one character because you are assigning these to the procedure parameters having datatype just varchar which can store only one character ). Also, your if has no else written before update statement.. Just make this changes and tell if you still face problems
harika26
Member
87 Points
141 Posts
Re: no error in code but still not getting values
May 16, 2012 11:14 AM|LINK
ok sure thanks