Click here to Skip to main content
15,917,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
it is not inserting the data where i am doing the mistak... , its showing catch error message


C#
string Patient_name = NameTxtBx.Text, Export_TO = ToTxtBx0.Text, repType = RadioButtonList2.SelectedValue  ;
                      int PatNoVal;
                      PatNoVal = Convert.ToInt32(PatNo.Text);
                      PatNoVal = int.Parse(PatNo.Text);
                      decimal PatID = decimal.Parse(PatID_NO.Text);
                      int? replay_To_type = Int16.Parse(DropDownList1.SelectedValue);
                      int idcount;
                         try
                          {
                              SqlConnection con =  new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
                              con.Open();
                              SqlCommand cmd = new SqlCommand;
                              cmd.CommandType = CommandType.StoredProcedure;
                              cmd.CommandText = "Transaction";
                              cmd.Parameters.AddWithValue(" @Patient ", Patient_name);
                              cmd.Parameters.AddWithValue("@E_TO ", Export_TO);
                              cmd.Parameters.AddWithValue ("@R_type ",repType);
                              cmd.Parameters.AddWithValue("@ReportType ",replay_To_type);
                              cmd.Parameters.AddWithValue(" @Patient_no  ",PatNoVal);
                              cmd.Parameters.AddWithValue(" @Patient_ID_NO ",PatID);
                              cmd.Parameters.Add("@idcount", SqlDbType.Decimal);
                              //idcount.Precision = 18;
                              //idcount.Scale = 0;
                              cmd.Parameters["@idcount"].Direction = ParameterDirection.Output;
                              cmd.Connection = con;
                              cmd.ExecuteNonQuery();
                              con.Close();
                              TextBox1.Text = cmd.Parameters["@RETURNOUT"].Value.ToString();
                              ClientScriptManager cs = Page.ClientScript;
                            cs.RegisterStartupScript(this.GetType(), "IDCount", "alert('"+cmd.Parameters["@RETURNOUT"].Value.ToString()+"');", true);
                         }
                          catch
                          {
                              Message("block 3:Error", this);

                          }



[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 30-Jun-12 22:11pm
v2

We can't tell for the same reason you can't: Your code hides the error.
Change the catch block:
C#
catch (Exception ex)
   {
   Message("Block 3: Error\nThe Reported fault is:\n" + ex.Message, this);
   }
That way, if the error message does not give you enough information, you can put a break point on the exception and view the detail.
 
Share this answer
 
Comments
Mohammed Abdul Muqeet 1-Jul-12 4:27am    
@sandeep...i have changed the line to
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Transaction";
and i hae
Mohammed Abdul Muqeet 1-Jul-12 4:29am    
@OriginalGriff ..
i have pasted your lines in my code it is not showing any message , or error ,from this lines its going to catch cmd.ExecuteNonQuery();
con.Close();
Mohammed Abdul Muqeet 1-Jul-12 4:33am    
This is my error in execption ...
Procedure or function 'Transaction' expects parameter '@Patient', which was not supplied.

my stored procedure
ALTER PROCEDURE [dbo].[Transaction]
(

@Patient nvarchar(50),
@E_TO nvarchar(50),
@R_type int,
@User_id uniqueidentifier,
@ReportType nvarchar(50),
@Patient_no int,
@Patient_ID_NO numeric(18,0),
@idcount numeric(18,0) output

)
AS
BEGIN

declare @tempid numeric(18,0)
set @tempid = 0;
declare @idcnt numeric(18,0)
select @idcnt =isnull( max(idcount),0) from Transactions where year(R_date)=year(getdate())
if (@idcnt =0)
set @tempid=1
else
set @tempid = @idcnt +1


INSERT INTO dbo.Transactions (Patient,E_TO,R_date,R_from,User_id,report_type,Patient_no,Patient_ID_NO,idcount)values (@Patient,@E_TO,getdate(),@R_type,@User_id,@ReportType,@Patient_no,@Patient_ID_NO,@tempid)

END
OriginalGriff 1-Jul-12 4:45am    
Take the spaces out!
The Parameter names are not trimmed before being passed to SQL:
cmd.Parameters.AddWithValue(" @Patient ", Patient_name);
Becomes:
cmd.Parameters.AddWithValue("@Patient", Patient_name);
You will need to do this for the others as well.

Mohammed Abdul Muqeet 1-Jul-12 4:51am    
yes i did .. brother i have one more issue .. when a user login , how can i save the user name in my table , you can see in my stored procedure there is @User_id , i want to save the user name in my table with every transaction ...
because its showing this error now..
Procedure or function 'Transaction' expects parameter '@User_id', which was not supplied.
Is it even compiling?

For instance, this line:
C#
SqlCommand cmd = new SqlCommand;
 
Share this answer
 
Comments
Mohammed Abdul Muqeet 1-Jul-12 5:03am    
?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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