Linq to sql , one column is inserting NULL value ,
-
This is my stored procedure and c# code .. the column Patient_ID_NO is not inserting any value , and i want to display idcount value in message box ,. 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 int, @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# code 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 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,Pat
-
This is my stored procedure and c# code .. the column Patient_ID_NO is not inserting any value , and i want to display idcount value in message box ,. 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 int, @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# code 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 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,Pat
Decimal PatID;
PatID = Convert.ToInt32(PatID_NO.Text);
PatID = int.Parse(PatID_NO.Text);Should that not be:
int PatID;
if (!int.TryParse(PatID_NO.Text, out PatID))
{
// Warn the user the value couldn't be parsed.
}The reason there's nothing in idcount is because you haven't set it to anything in your stored procedure. Try
SET @idcount = SCOPE_IDENTITY()
Finally, could you please use the <pre> tag to format your snippets? I had a real problem reading your post. When you enter a snippet, highlight it in the editor and hover over the code tag just above the message editor - a drop down list appears allowing you to choose the appropriate language.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
Decimal PatID;
PatID = Convert.ToInt32(PatID_NO.Text);
PatID = int.Parse(PatID_NO.Text);Should that not be:
int PatID;
if (!int.TryParse(PatID_NO.Text, out PatID))
{
// Warn the user the value couldn't be parsed.
}The reason there's nothing in idcount is because you haven't set it to anything in your stored procedure. Try
SET @idcount = SCOPE_IDENTITY()
Finally, could you please use the <pre> tag to format your snippets? I had a real problem reading your post. When you enter a snippet, highlight it in the editor and hover over the code tag just above the message editor - a drop down list appears allowing you to choose the appropriate language.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
i will try ur code in my office . hope it will work... i have auto increment value in idcount it will increment till one year when the next year start it will change to 1 again... i tried SET @idcount = SCOPE_IDENTITY().. but the value which is in idcount column is different than scope identity,which i try to display in message box ... how can i use return ? in this stored procedure so that the value which i am inserting should be displayed..?