代码如下:
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;