刘沛霖啊 2019-06-21 20:45 采纳率: 0%
浏览 672

其他信息: Incorrect syntax near 'FORM'.请问这个是什么原因造成的

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _20190619
{
public partial class Form1 : Form
{
string strcon = @"Data Source=(localdb)\Projects;Initial Catalog=master;Integrated Security=True;";
DataSet myst = new DataSet();
SqlDataAdapter myda;
public Form1()
{
InitializeComponent();
btnSeach_Click(null, null);
}

    private void btnInsert_Click(object sender, EventArgs e)
    {
        SqlConnection sqlcon = new SqlConnection(strcon);
        try
        {
            string stuID = StuID.Text.Trim();
            string stuName = StuName.Text.Trim();
            string stuXB;
            if (RbtnMale.Checked)
            {
                stuXB = "男";
            }
            else
            {
                stuXB = "女";
            }
            string stuBirth = dateTimePicker1.Value.ToShortDateString().Split(' ')[0];
            string stuMajor = StuMajor.Text.Trim();
            string stuCredit = StuCredit.Text.Trim();
            SqlCommand command = new SqlCommand();
            command.CommandText = "INSERT INTO XSB(XH,XM,XB,CSRQ,ZY,ZYF)VALUES('" + stuID + "','" + stuName + "','" + stuXB + "','" + stuBirth + "','" + stuMajor + "','" + stuCredit + "')";
            command.CommandType = CommandType.Text;
            command.Connection = sqlcon;
            sqlcon.Open();
            myda = new SqlDataAdapter(command);
            myda.Fill(myst, "XSB");
            MessageBox.Show("插入成功!", "消息", MessageBoxButtons.OK);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        finally
        {
            sqlcon.Close();
        }
    }
    private void btnSeach_Click(object sender, EventArgs e)
    {
        using (SqlConnection sqlcon = new SqlConnection(strcon))
        {
            sqlcon.Open();
            string sql = "SELECT*FORM XSB";
            SqlCommand command = new SqlCommand(sql, sqlcon);
            myda = new SqlDataAdapter(command);
            myst.Tables.Clear();
            myda.Fill(myst, "XSB");
            dgvAllStu.DataSource = myst.Tables["XSB"];
        }
    }
   }
}

  • 写回答

2条回答 默认 最新

  • threenewbee 2019-06-21 22:01
    关注

    string sql = "SELECT*FORM XSB";
    ->
    string sql = "SELECT * FROM XSB";

    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?