LINQ to sql一列未插入 [英] LINQ to sql one column is not inserting

查看:75
本文介绍了LINQ to sql一列未插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的存储过程和c#代码,Patient_ID_NO没有插入它插入NULL的值,我想在消息框中设置idcount值。我怎么能在这个过程中做



  ALTER PROCEDURE [dbo]。[交易] 

( 

      

       @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输出

   ) 

AS 

BEGIN 

           

         声明@tempid numeric(18,0)

         设置@tempid = 0;  

         声明@idcnt数字(18,0)

         从交易中选择@idcnt = isnull(max(idcount),0),其中年份(R_date)=年(getdate()) 

          if(@idcnt = 0) 

         设置@ tempid = 1 

          else 

         设置@tempid = @idcnt +1 

    INSERT INTO dbo.Transactions 

    (

  患者,E_TO,R_date,R_from,[User_id],

   report_type,Patient_no,Patient_ID_NO,idcount

  )

   价值

    (

   @ Patient,@ E_TO,getdate(),@ R_type,@ User_id,@ ReportType,@ Patient_no,@ Patient_ID_NO,@ tempid

   )

    END 


< p style ="margin-bottom:18px; padding-right:0px; outline:0px; font-size:13px; vertical-align:baseline; background-color:#f0f3f4; color:#222222; font-family:'Segoe UI',Tahoma,Arial,Helvetica,sans-serif">
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 =新SIDC();

int n;

n = a.valid_re_int(PatID_NO .Text);

if(n> 3)

{

消息(< 错误以及make确定标识号"",此);

返回;

}

其他

PatID_NO.Focus();

}



else



PatID_NO.Focus();

试试
{

if(NameTxtBx.Text =="" || ToTxtBx0.Text =="" || DropDownList1.SelectedIndex == 0 || RadioButtonList2.SelectedIndex == -1 ||(PatID_NO。 Text =="")||(Convert.ToUInt64(PatNo.Text)< = 0)||(Convert.ToUInt64(PatNo.Text)> 200000000)))
{

消息("错误:请确保正确输入所有字段",this);

返回;

 }

其他¥ b $ b {

try

{

string Patients_name = NameTxtBx.Text,Export_TO = ToTxtBx0.Text,repType = RadioButtonList2.SelectedValue;



int PatNoVal;

PatNoVal = Convert.ToInt32(PatNo.Text);

PatNoVal = int.Parse(PatNo.Text);

  DateTime today = Convert.ToDateTime(DateTime.Now.ToShortDateString());

  ; System.Nullable< decimal> idcount = null;

int?replay_To_type = Int16.Parse(DropDownList1.SelectedValue);

try


< p style ="margin-bottom:18px;填充右:0像素;概要:0像素;字体大小:13像素;垂直对齐:基线;背景色:#f0f3f4;颜色:#222222; font-family:'Segoe UI',Tahoma,Arial,Helvetica,sans-serif">
{



TransDataContext db = new TransDataContext();



试试
{

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



foreach(交易中的交易交易)

{

  Response.Write("您的ID为" + Transaction.idcount +"< br>");

}



}

catch

{

消息("块3:条目表单中有错误必填项,请联系计算机部",this);
$


}



 }

catch

{

消息("块2:错误联系您的系统管理员",这个);

}



PatNo.Text ="" ;; $
NameTxtBx.Text ="" ;;

ToTxtBx0.Text ="" ;;
$
DropDownList1.SelectedIndex = -1;

RadioButtonList2.SelectedIndex = -1;



}

catch

{

消息("خطأ:ERROR 20",this);

}



}

}

catch

{

消息(" 错误:确保正确输入数据   ",this);

}

}



protected void DropDownList1_DataBound(object sender,EventArgs e)

{

DropDownList1.Items.Insert(0," - Select One - ");

}



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



公共小数?PatID {get; set;}

}

}



新生于开发

解决方案

如果只有一列没有插入那么..你需要放置断点并遍历所有变量赋值代码,直到你点击db.Transaction。在执行函数之前检查值。


在后端SQL端,打开SQL Server配置文件并跟踪哪些参数传递到并通过存储过程执行。


然后你可以放大哪个部分是导致问题。


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.

 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
    )
   END 

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);
 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);
//var q = db.Transaction(Patient_name, Export_TO, today, replay_To_type, null, repType, PatNoVal, 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; }
}
}


New born in developing

解决方案

If only one column is not inserting then.. you need to put break points and go through all the variable assignment codes, until you hit db.Transaction. Check the values before execute the function.

At the backend SQL side, turn on the SQL Server Profile and trace which parameters are passing to and executed through the Stored Procedure.

Then you can zoom in which part is causing the issue.


这篇关于LINQ to sql一列未插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆