小编mot*_*375的帖子

尝试使用sql查询INSERT INTO在表中插入一行

我试图使用INSERT INTOSQL查询将新行插入我的数据库.我不确定我做错了什么,因为我不是更有经验的程序员.

我按下按钮时尝试将整数值1添加到问题类型列.我的主键自动递增,因此不应该是一个问题,因为所有其他列都可以为NULL.

INSERT INTO dbo.Questions (Question Type)
VALUES (1)
Run Code Online (Sandbox Code Playgroud)

当我按OK查询此查询时,会显示错误说明:

尝试创建参数化查询时发生错误:

函数参数列表出错:'Type'无法识别.不完整的参数或列表.无法解析查询文本.

这是我要添加到的表的代码:

CREATE TABLE [dbo].[Questions] (
[QuestionID]     INT           IDENTITY (1, 1) NOT NULL,
[Actual answer]  NVARCHAR (50) NULL,
[Question Space] NVARCHAR (50) NULL,
[Question Type]  INT           NULL,
PRIMARY KEY CLUSTERED ([QuestionID] ASC)
);
Run Code Online (Sandbox Code Playgroud)

c# sql database sql-server sql-insert

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

将整数和字符串插入SQL Server数据库c#的问题

我无法将整数值[Question Type]和字符串[Question Space]同时插入到我的数据库中同一行.每当我点击按钮并尝试执行错误时,会说:

System.Data.dll中发生了类型为"System.Data.SqlClient.SqlException"的未处理异常

附加信息:'('附近的语法不正确.

码:

SqlCommand command5 = new SqlCommand("INSERT INTO ([Question Space], [Question Type]) Questions VALUES ('@QuestionText', '@checkedradiobutton')", connect);
command5.Parameters.AddWithValue("@QuestionText", QuestionText);
command5.Parameters.AddWithValue("@checkedradiobutton", checkedradiobutton);

command5.ExecuteNonQuery();
Run Code Online (Sandbox Code Playgroud)

我很感激任何人都能给我的帮助.

如果你想看到,这是按钮的整个代码:

private void button1_Click(object sender, EventArgs e)
{
    string connectionString = ConfigurationManager.ConnectionStrings["myconnectionstring"].ConnectionString;

    SqlConnection connect = new SqlConnection(connectionString);
    connect.Open();

    int checkedradiobutton = 0;

    if(radioButton1.Checked)
    {
        checkedradiobutton = 1;
    }
    else if(radioButton2.Checked)
    {
        checkedradiobutton = 2;
    }
    else if(radioButton3.Checked)
    {
        checkedradiobutton = 3;
    }

    string QuestionText = QuestionBox.Text;

    SqlCommand command5 = new SqlCommand("INSERT INTO ([Question …
Run Code Online (Sandbox Code Playgroud)

c# database sql-server sql-insert

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

System.IndexOutOfRangeException错误SQL SELECT查询无法读取从我的表中选择的数据

我有关于SQL的SELECT语句,我只是想查看从表中检索到的内容以检查它是否正常工作但是我遇到了问题!

我不确定为什么我的代码不起作用,每当我尝试运行代码时出现错误说:System.IndexOutOfRangeException,我似乎无法找到解决方案.

我会非常感谢任何帮助!

public partial class CurrentlySetTestForm : Form

{
    Timer loopTimer = new Timer();
    private string CurrentQuestionID { get; set; }
    private string QuestionSpace { get; set; }
    public CurrentlySetTestForm()
    {
        InitializeComponent();
    }

    private void CurrentlySetTestForm_Load(object sender, EventArgs e)
    {

        string y = GlobalVariableClass.Signedinteacher;

        Convert.ToInt32(y);

        string connectionString = ConfigurationManager.ConnectionStrings["myconnectionstring"].ConnectionString;
        SqlConnection connect = new SqlConnection(connectionString);

        connect.Open();

        SqlCommand command18 = new SqlCommand("SELECT MIN([QuestionID]) FROM QuestionStudentAssociation WHERE ( [StudentID]=@Signedinstudent AND [StudentAnswer]=NULL )", connect);
        command18.Parameters.AddWithValue("@Signedinstudent", y);

        var reader = command18.ExecuteReader();
        while (reader.Read())
        { …
Run Code Online (Sandbox Code Playgroud)

c# sql sql-server select messagebox

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

Excel编程 - 如果声明

我之前编写过C#编码,并且知道所有与循环和语句有关的基础知识.我一直在尝试在excel上创建一个简单的IF语句,但每次尝试运行它时都会出现一个非常无用的错误.我想知道是否有人能指出我在这里做错了什么 -

我只是想输出"是"如果单元格h14大于250或小于250且单元格I14大于0.15或小于-0.15则输出"否"

这就是我提出的但它似乎不起作用: IF((H14>=250 OR H14<=-250) AND (I14 >= 0.15 OR I14 <= -0.15),"Yes", "No")

非常感谢

excel if-statement excel-formula

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