小编das*_*ash的帖子

参数化查询和 NULL DateTime 值

我正在开发一个程序,该程序从访问数据库中提取字符串字段,从日期中分离出名称(名字和姓氏),然后将名称与日期分开保存在不同的访问数据库中。

除了一些日期值为空之外,我已经完成了所有工作,因此我需要对 SQL 进行参数化,但我无法弄清楚如何使参数化工作。

我已经为变量输入了虚拟值,并将它们添加到表格中就好了。我已经删除了下面代码片段中的其他变量,因为它们都重复了那里的内容。os 是一个包含结构中数据的列表。

string sqlcmd = "INSERT INTO signatures VALUES ('" + os.QASignature + "', 'QADate = @QADATE'";
System.Data.OleDb.OleDbCommand SQLCommand = new System.Data.OleDb.OleDbCommand(sqlcmd, Connection);
using (SQLCommand)
{
    SQLCommand.Parameters.Add("@QADATE", System.Data.OleDb.OleDbType.Date).Value = os.QADate;
    SQLDataReader = SQLCommand.ExecuteReader();
}
Run Code Online (Sandbox Code Playgroud)

c# sql ms-access ms-access-2007

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

Insert的ExecuteNonQuery()

你能告诉我这段代码有什么问题吗?

我是否需要使用DataAdapter插入表格?

我知道没问题connectionString,因为我在Server Explorer上测试了它.

    Dim mydao As New Connection
    Dim connectionString As String = mydao.GetConnectionString()
    Dim connection As New SqlConnection(connectionString)
    Dim cmd As New SqlCommand

Public Function add(ByVal area As String, ByVal user As String) As Integer

        cmd.CommandText = "INSERT into Area (Area, user) VALUES ('" + area + "','" + user + "')"
        Try
            connection.Open()
            Dim cant As Integer = cmd.ExecuteNonQuery()'it throws exception here
            connection.Close()
            Return cant
        Catch ex As Exception
            Console.WriteLine(ex.Message)
            Return 0
        End …
Run Code Online (Sandbox Code Playgroud)

vb.net insert sql-server-2008 visual-studio executenonquery

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

输出选项卡将字符串分隔为文件

我有以下工作正常:

    StreamWriter outputFile = new StreamWriter(@"C:\out.txt");

    string header =  "ProgramDate" +  "," +
                     "ProgTime";

    outputFile.WriteLine(header);

    outputFile.Close();
Run Code Online (Sandbox Code Playgroud)

而不是以逗号分隔,如何使其以制表符分隔.或者如何以制表符分隔开头?我在网上搜索但找不到答案.

c#

-1
推荐指数
1
解决办法
7892
查看次数

输入字符串的格式不正确.param.Value = Int32.Parse(shipZipCodeTxt.Text);

我一直收到输入字符串格式不正确的错误.我不明白为什么会这样.我正在尝试写入我的数据库,而Zip代码是一个数字.我已经尝试将其更改为字符串,但这会导致在执行非查询时缺少参数.

Input string was not in a correct format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error: 


Line 130:               param.DbType = DbType.Int32;
Line 131:               param.Direction = ParameterDirection.Input;
Line 132:               param.Value = Int32.Parse(shipZipCodeTxt.Text);
Line 133:                       
Line 134:               comm.Parameters.Add(param); 

Source File:     Line: 132 

Stack Trace: 


[FormatException: …
Run Code Online (Sandbox Code Playgroud)

c# database asp.net

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

在一个范围内查找可以除以5的数字

我的任务是:编写一个程序,读取两个正整数并打印它们之间存在多少个数字,使得除以5的提示为0(含).示例:p(17,25)= 2.

Console.Write("Enter min: ");
            int min = int.Parse(Console.ReadLine());
            Console.Write("Enter max: ");
            int max = int.Parse(Console.ReadLine());
            Console.WriteLine("The numbers devidable by 5 without remainder from {0} to {1} are: ",min,max);
            for (int i = min; i <= max; i++)
            {
                if (i % 5 == 0)
                {

                    Console.WriteLine(i);
                }
            }
Run Code Online (Sandbox Code Playgroud)

这将打印出范围内可分为5的数字...如何计算有多少数字并在控制台中打印计数?

c#

-2
推荐指数
1
解决办法
1964
查看次数