没有将任何行插入到DataTable中

时间:2019-03-08 19:46:25

标签: c# sql class login datatable

尝试创建登录功能。我创建了一个类,该类具有填充来自sql查询的数据表的功能,但无法正常工作。没有错误就没有数据插入。

这是我的登录函数类:

namespace GymCalculator
{
    public class LoginFunction
    {
        public DataTable Login (string username, string pword)
        {
            using (SqlConnection connection = new System.Data.SqlClient.SqlConnection(ConnectionHelper.CnnVal("GymDB"))) {
                string query = ("Select * from [USER] where username = '{username}'  and password = '{pword}'");
                SqlDataAdapter sda = new SqlDataAdapter(query, connection);
                DataTable dtbl = new DataTable();
                sda.Fill(dtbl);
                return dtbl;
            }
        }
    }
}

这是我的代码来调用类和函数:

public partial class Login : Form
{
    public Login()
    {
        InitializeComponent();
    }

    private void Loginbtn_Click(object sender, EventArgs e)
    {
        var LoginFunction = new LoginFunction();
        var DataTable = new DataTable();

        DataTable = LoginFunction.Login(Usernametxt.Text, Passwordtxt.Text);
        if (DataTable.Rows.Count == 1) {
            CalculatorMain calculatorMain = new CalculatorMain();
            this.Hide();
            calculatorMain.Show();
        } else {
            MessageBox.Show("You entered the wrong username or password");
        }
    }
 }

1 个答案:

答案 0 :(得分:0)

这是我最后的工作代码...我最终使用了存储过程。

$(document).ready(function($) {
      $(".summernote_custom").summernote({
           height: 200,
           styleTags: ['p', 'h1', 'h2'],
           toolbar: [
                 ['style', ['bold', 'italic', 'underline', 'clear']],
                 ['para', ['ul', 'ol', 'paragraph','style']],
                 ['fontname', ['fontname']],
                 ['fontsize',['fontsize']],
                 ['insert', ['picture','link']]
           ],
           dialogsInBody: true,
            callbacks: {
               onImageUpload: function(files) {
                 uploadImage(files[0],$(this));
               }
             }
         });
    });

    function uploadImage(image,editor) {
      var data = new FormData();
      data.append("image",image);
      data.append("name", "resource");
      $.ajax ({
        data: data,
        type: "POST",
        url: "#{ajax_upload_doctor_attachments_path}",
        cache: false,
        contentType: false,
        processData: false,
        success: function(data) {
          editor.summernote("insertImage", "#{HOST}" + data.url, function ($image) {
            $image.css('width', '100%');
            $image.attr('data-filename', 'retriever');
          });

        },
        error: function(data) {
          console.log(data);
        }
      });
    }