求助各位大神帮忙解决 C#

图片说明
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void button1_Click(object sender, EventArgs e)
    {
        string con;
        con = "Server=.;Database=db;Trusted_Connection=SSPI";
        SqlConnection mycon = new SqlConnection(con);
        mycon.Open();
        string sql = "Select username from Login where username='" + textBox1.Text.Trim() + "'and userpws='" + textBox2.Text.Trim() + "'";
        SqlCommand cmd = new SqlCommand("sql", mycon);
        cmd.CommandType = CommandType.Text;
        mycon.CommandText = sql;

1个回答

mycon.CommandText = sql;
应该是
cmd.CommandText = sql;

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问