小编ban*_*daa的帖子

参数名称前面的@有什么作用?

@在参数SQL查询前面插入符号时会做什么?

例如:

using (SqlCommand cmd = new SqlCommand("INSERT INTO [User] values (@Forename, @Surname, @Username, @Password)", con))
{
    cmd.Parameters.AddWithValue("@Forename", txtForename.Text);
    cmd.Parameters.AddWithValue("@Surname", txtSurname.Text);
    cmd.Parameters.AddWithValue("@UserName", txtUsername.Text);
    cmd.Parameters.AddWithValue("@Password", txtPassword.Text);

    cmd.ExecuteNonQuery();
}
Run Code Online (Sandbox Code Playgroud)

c# sql visual-studio winforms

6
推荐指数
2
解决办法
289
查看次数

如何从DataGridView控件中打印值

我有一个具有DataGridView控件的应用程序,当按下"打印"按钮时,该控件保存我想要打印的数据.

到目前为止,我已经有了"打印"按钮,但是当我在应用程序上打印时,页面出现空白!

如何编辑代码以启用数据打印?

public partial class frmViewBookings : Form
{
    private void btnClose_Click(object sender, EventArgs e)
    {
        Form3 mainpage = new Form3();
        mainpage.Show();
        this.Close();
    }

    private void frmViewBookings_Load(object sender, EventArgs e)
    {
        this.bookingTableAdapter.Fill(this.usersDataSet1.Booking);
    }

    private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
    {
        var myPaintArgs = new PaintEventArgs
        (
            e.Graphics,
            new Rectangle(new Point(0, 0), this.Size)
        );

        this.InvokePaint(dataGridView1, myPaintArgs);
    } 

    private void btnPrint_Click(object sender, EventArgs e)
    {
        printDocument1.Print();
    }
}
Run Code Online (Sandbox Code Playgroud)

c# printing datagridview winforms

5
推荐指数
1
解决办法
4万
查看次数

检查数据库中是否已存在用户名

我正在尝试检查数据库表"user"以查看是否存在"用户名",以便无法再次创建相同的用户名.我希望这是一个验证器,所以如果用户名存在,消息框将显示它存在.

请指导我完成此操作,到目前为止,我有以下代码添加并检查用户名是否存在:

private void btnSignupNew_Click(object sender, EventArgs e)
        {

           if (txtUsername.Text == "")
           {
               errorUsername.SetError(txtUsername, "Enter A Username");
           }

           else if (txtPassword.Text == "")
           {
               errorPassword.SetError(txtPassword, "Enter A Valid Password");
           }

               //so if there isnt no error in the fields itll go on and add the data in to the database.
           else{

            //instance of sqlConnection
            SqlConnection con = new SqlConnection("Data Source=etc");

            //instance of sqlCommand
            SqlCommand cmd = new SqlCommand("INSERT INTO [User] values ('" + txtForename.Text + "', '" + txtSurname.Text …
Run Code Online (Sandbox Code Playgroud)

c# validation username winforms visual-studio-2012

1
推荐指数
1
解决办法
3万
查看次数