Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my stored procedure and c# code, Patient_ID_NO is not inserting the value it is inserting NULL, and i want to shaoe idcount value in message box. how can i do this process.
SQL
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(10,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 


C#
public static void Message(String message, Control cntrl)
{
ScriptManager.RegisterStartupScript(cntrl, cntrl.GetType(), "alert"
, "alert('" + message + "');", true);
}
 protected void Button1_Click(object sender, EventArgs e)
{
if (PatID_NO.Text != "")
{
SIDC a = new SIDC();
int n;
n = a.valid_re_int(PatID_NO.Text);
if (n > 3)
{
Message("Error as well as make sure identification number"", this);
return;
}
else
PatID_NO.Focus();
}

else

PatID_NO.Focus();
try
{
if (NameTxtBx.Text == "" || ToTxtBx0.Text == "" || DropDownList1.SelectedIndex == 0 || RadioButtonList2.SelectedIndex == -1 || ( PatID_NO.Text == "")|| (Convert.ToUInt64(PatNo.Text) <= 0) || (Convert.ToUInt64(PatNo.Text) > 200000000))
{
Message("Error: Please make sure that all fields are entered correctly", this);
return;
 }
else
{
try
{
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;
 PatID = Convert.ToInt32(PatID_NO.Text);
 PatID = int.Parse(PatID_NO.Text);
 DateTime today = Convert.ToDateTime(DateTime.Now.ToShortDateString());
 System.Nullable<decimal> idcount = null;
int? replay_To_type = Int16.Parse(DropDownList1.SelectedValue);
try

{

TransDataContext db = new TransDataContext();

try
{

var q = db.Transaction(Patient_name, Export_TO,replay_To_type,null,repType,PatNoVal,PatID,ref idcount);

foreach (Transaction Transaction in Transactions)
{
 Response.Write("your id is" + Transaction.idcount + "<br>");
}

}
catch
{
Message("block 3:There is an error in the entry form required, please contact the Department of Computer", this);

}

 }
catch
{
Message("block 2: ERROR CONTACT YOUR SYSTEM ADMINISTRATOR", this);
}

PatNo.Text = "";
NameTxtBx.Text = "";
ToTxtBx0.Text = "";
DropDownList1.SelectedIndex = -1;
RadioButtonList2.SelectedIndex = -1;

}
catch
{
Message(" ERROR 20", this);
}

}
}
catch
{
Message("Error: Make sure you enter the data correctly  ", this);
}
}

protected void DropDownList1_DataBound(object sender, EventArgs e)
{
DropDownList1.Items.Insert(0, "--Select One--");
}

public IEnumerable<transaction> Transactions { get; set; }

public decimal? PatID { get; set; }
}
}</transaction></br></decimal>
Posted
Updated 19-Jun-12 20:56pm
v2

Hi ,
Check this
SQL
 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(10,0),
            @idcount numeric(18,0)=NULL 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
    )
   SELECT @idcount = SCOPE_IDENTITY()
   END 

Update your DBML and Check
Make break point check if there is value for PatID
and if it have value make sure it's already mapped right on DBML
C#
Decimal PatID;
 PatID = Convert.ToInt32(PatID_NO.Text);


Best Regards
M.Mitwalli
 
Share this answer
 
v2
i have tested ur stored procedure . its show the idcount not from the table . the table value is inserting 7 the display number is showing 11,it is displaying scope identity number.i just want to display the value which is inserting in idcount .
 
Share this answer
 
please any one , give me solution.....
 
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