小编Oli*_*bes的帖子

如何在LINQ中使用OUT参数

我的存储过程使用一个输出参数.我想在My MVC应用程序中使用out参数.我可以知道如何在LINQ中使用参数.我在做什么

[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.Usp_Insert_Id")]
public int Usp_Insert_Id(
    [global::System.Data.Linq.Mapping.ParameterAttribute(Name="EmpID", DbType="Int")]
    System.Nullable<int> EmpID)
{
    IExecuteResult result =
       this.ExecuteMethodCall(
            this,
            ((MethodInfo)(MethodInfo.GetCurrentMethod())),
            EmpID);
    return ((int)(result.ReturnValue));
}
Run Code Online (Sandbox Code Playgroud)

在我正在使用的控制器中

int output = 0;
output = dataContext.Usp_Insert_Id(Id,ref output);
Run Code Online (Sandbox Code Playgroud)

我的存储过程就是这样

create procedure Usp_Insert_Id ( @Id
int, @Return int out ) as insert into
Emplyee(ID,Date_TIME,Status)
values (@Id,GETDATE(),1)

select @Return=SCOPE_IDENTITY()
Run Code Online (Sandbox Code Playgroud)

告诉我我做错了什么?

c# stored-procedures linq-to-sql

5
推荐指数
1
解决办法
7224
查看次数

Access中有多个LEFT JOIN

我有以下查询,适用于MySQL:

DELETE `test1`, `test2`, `test3`, `test4` FROM
`test1` LEFT JOIN `test2` ON test2.qid = test1.id
LEFT JOIN test3 ON test3.tid = test2.id
LEFT JOIN test4.qid = test1.id
WHERE test1.id = {0}
Run Code Online (Sandbox Code Playgroud)

但它不适用于MS Access.我试图在LEFT JOIN它周围添加括号,但它在FROM子句中给出了语法错误.那么这个查询应该怎样才能在MS Access中工作?

sql ms-access jet sql-delete

4
推荐指数
1
解决办法
3万
查看次数

使用Data Reader访问两个数据库

我正在尝试使用ADO.NET开发应用程序.我在两个不同的数据库中有两个表.他们每个人都有一部分完整的数据.现在我需要编写一个查询,以便我能够从两个表中获取完整的记录.例如,表1具有Index_no,emp_ID和联系号.表2包含index_no,emp_name,salary和dept.index_no对于每个表中的相同记录部分是相同的.以下是获取薪水<20000的所有记录的代码.

sqlCmd2 = new SqlCommand("SELECT * FROM table1 WHERE Index_No =@Index_No",
                         TestCon);
int i = 0; 
while (reader.Read()) {
    ListBox1.Items.Add(reader.GetInt32(0) + "  -   " + 
      reader.GetString(1) + "  -   " + reader.GetString(2));
    //  Name.Text += reader["Name"] + "<br />"; ;
    // Depart.Text += reader["Depart"] + "<br />"; ;
    array1[i] = reader.GetInt32(0);
    i++;
}

sqlCmd2.Parameters.Add("@Index_No", System.Data.SqlDbType.Decimal);
i = 0;
do {
    sqlCmd2.Parameters["@Index_No"].Value = array1[i];
    reader1 = sqlCmd2.ExecuteReader();
    reader1.Read();
    ListBox2.Items.Add(reader1.GetString(1));
    i++;
} while (i < array1.Length);
Run Code Online (Sandbox Code Playgroud)

这个问题是我从table2只得到一个记录信息,而对于表1,我得到了所有想要的记录信息.do-while循环似乎仅在一次迭代后终止.

c# sql

4
推荐指数
1
解决办法
1203
查看次数

选中ComboBox到文本框

我正在创建一个从数据库中提取数据的表单,并提供两个组合框.ComboBox1以"名字姓氏"格式显示员工姓名.ComboBox2以"Last,First"格式显示Employee名称.这些名字毫不费力地进入组合框.

我试图弄清楚如何做的是,一旦用户从下拉框中选择一个名称,它将根据查询中的其他信息填充某些文本框,例如textBox1,textBox2.

我试图使用

textBox1.Text = comboBox1.SelectedItem;
Run Code Online (Sandbox Code Playgroud)

但是,我得到一个错误说明:不能隐式地将类型'object'转换为'string'.存在显式转换(您是否错过了演员?)

这是我目前的代码.我故意遗漏了对数据库的连接查询.

public partial class Employees : Form
{
    public Employees()
    {
        InitializeComponent();

        //Connect to database for Employees Table Headers
        SqlConnection myConnection = new SqlConnection(@"Server=Server...");

        try {
            myConnection.Open();
            string SqlDataPull = String.Format("SELECT * FROM Employees WHERE Lname IS NOT NULL {0} ORDER By Lname", (checkBox1.Checked ? "AND Active='Y'" : ""));
            SqlCommand cmd = new SqlCommand(SqlDataPull, myConnection);
            cmd.CommandType = CommandType.Text;
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read()) {
                string strEmployee = String.Format("{0}  {1}", dr["Fname"], dr["Lname"]);
                comboBox1.Items.Add(strEmployee); …
Run Code Online (Sandbox Code Playgroud)

c# combobox visual-studio-2010 winforms

4
推荐指数
2
解决办法
5万
查看次数

在打开的 Windows 资源管理器上选择一个文件

我有以下 cod,它将启动 Windows 资源管理器并选择一个文件并最大化资源管理器。然后它将查找 Windows 资源管理器并将其最小化。我做了最大化-最小化,这样我就不必手动执行此操作(懒惰,我知道)。我在我的代码中设置了此设置,仅在文件夹未打开时触发。如果它是打开的,那么只需运行最小化部分。这是代码:

If Not FolderIsOpen Then
    Dim curProcess As Process = New Process()
    With curProcess
        With .StartInfo
            .FileName = "explorer.exe"
            Dim MinimizeName As String = RegScoringWorkbookName.Replace(".xlsm", ".zip")
            .Arguments = String.Format("/select, ""{0}""", MinimizeName)
            .WindowStyle = ProcessWindowStyle.Maximized
        End With
        .Start()
    End With
    Thread.SpinWait(100000000)
    For Each IWindow As InternetExplorer In SHWindows
        If IWindow.Name = "Windows Explorer" Then
            Dim GetURIPath As New Uri(IWindow.LocationURL)
            If GetURIPath.LocalPath.ToLower.Equals(FolderName) Then
                ShowWindow(CType(IWindow.HWND, IntPtr), SW_SHOWMINIMIZED)
                Exit For
            End If
        End If
    Next IWindow
Else
    For Each …
Run Code Online (Sandbox Code Playgroud)

vb.net

4
推荐指数
1
解决办法
2629
查看次数

为什么我不能在IOrderedQueryable上调用Skip?

我这样回来了IOrderedQueryable<T>:

response.Data = Expressions
    .ApplySorts(request, result)
    .Skip(request.Skip)
    .Take(request.Take)
    .ToList();
Run Code Online (Sandbox Code Playgroud)

这是我的类,其中包含一个返回的方法IOrderedQueryable<T>.

public static class Expressions
{
    public static IOrderedQueryable<T> ApplySorts<T>(
        DataRequest request, IQueryable<T> items)
        {
            var sorts = request.Sort;

            if (sorts != null)
            {
                foreach (var sort in sorts)
                {
                    items = items.OrderBy(sort.Field + " " + sort.Dir);
                }
            }

            return (IOrderedQueryable<T>)items;
        }
}
Run Code Online (Sandbox Code Playgroud)

但在运行时我收到此错误:

{"方法'Skip'仅支持LINQ to Entities中的排序输入.必须在方法'Skip'之前调用'OrderBy'方法."}

请注意,目前没有任何种类; 但是,返回值ApplySorts<T>()仍然应该返回Skip()期望的类型,不是吗?

c# linq entity-framework

4
推荐指数
1
解决办法
637
查看次数

如何从类中的函数返回异常

createFolding我正在我的类中创建一个名为 的函数clsFolding。我通过这个函数在数据库中插入一些值createFolding。所以,我int status_id从函数返回(如果正常则返回 1,如果错误则返回 0)。如果出现错误(if),我还想从函数返回异常消息,status_id =0但我不知道如何从函数返回多个值。这是我在课堂上完成的代码clsFolding

public class clsFolding
{
    public static string ConStr = ConfigurationManager.ConnectionStrings["FazalConstructions.Properties.Settings.ConnString"].ConnectionString;
    public static SqlConnection con;
    public static SqlCommand cmd = new SqlCommand();
    public static int status_id;
    public static Exception ex;

    public static int createFolding(int id, string name, int qty, string narration, DateTime dt)
    {
        try
        {
            con = new SqlConnection(ConStr);
            con.Open();
            cmd = new SqlCommand("INSERT INTO tblFolding(FoldingID, Name,Quantity,Narration,DateTime)VALUES(@id, @name, @qty, @narration,@dt)", con);

            cmd.Parameters.AddWithValue("@id", id);
            cmd.Parameters.AddWithValue("@name", …
Run Code Online (Sandbox Code Playgroud)

c# exception

4
推荐指数
1
解决办法
2万
查看次数

C# ICommand Can Execute

I was trying to understand the ICommand interface. I built an application with a button that uses a class called RelayCommand which inherits from ICommand. The class looks like this:

    class RelayCommand : ICommand
{
    private Action<object> _action;
    public RelayCommand(Action<object> action)
    {
        _action = action;
    }

    public bool CanExecute(object parameter)
    {
        return true;
    }

    public void Execute(object parameter)
    {
        if(parameter != null)
        {
            _action(parameter);
        }
        else
        {
            _action("Hello World");
        }
    }

    //We need to include CanExecuteChange when using the Interface …
Run Code Online (Sandbox Code Playgroud)

c# wpf interface icommand

4
推荐指数
1
解决办法
1618
查看次数

为什么 console.writeline 在 Visual Studio for Mac 中不起作用?

我有一个控制台应用程序,我刚刚在 Visual Studio for Mac 和 Program.cs 中自动创建的代码显然有错误。这是代码:

using System;

namespace Console
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

因为它把它放在那里而不是我,你会期望它工作,但它没有,它出现了这个错误:

Console/Program.cs(13,13):错误 CS0234:命名空间“控制台”中不存在类型或命名空间名称“WriteLine”(您是否缺少程序集引用?)(CS0234)(控制台)

如何解决这个问题?

谢谢!

c# visual-studio-mac

4
推荐指数
1
解决办法
1226
查看次数

随机数猜谜游戏

我正在做一个随机数猜测游戏,计算机认为是1-100之间的数字.然后它会询问你它是什么,并告诉你你是对还是错.但是,每当我调试时,由于某种原因它会说它高于或低于实际随机数.此外,它同时说出其中两个陈述.另外,我不知道怎么说这个人已经猜了多少次.这是我不成功的代码.

static void Main(string[] args) 
{
    Random random = new Random();

    int returnValue = random.Next(1, 100);
    int Guess = 0;

    Console.WriteLine("I am thinking of a number between 1-100.  Can you guess what it is?");

    while (Guess != returnValue)
    {
        Guess = Convert.ToInt32(Console.Read());

        while (Guess < returnValue)
        {
            Console.WriteLine("No, the number I am thinking of is higher than " + Guess + " .  Can you guess what it is?");
            Console.ReadLine();

        }
        while (Guess > returnValue)
        {
            Console.WriteLine("No, the number I …
Run Code Online (Sandbox Code Playgroud)

c# numbers

3
推荐指数
1
解决办法
4万
查看次数