Home > Net >  Why after the load data button data show not to come out, what's wrong?
Why after the load data button data show not to come out, what's wrong?

Time:09-25

using System;
Using System. Collections. Generic;
Using System.Com ponentModel;
Using System. The Data;
Using System. Drawing;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;
Using System. Windows. Forms;
Using System. The Data. SqlClient.

The namespace demo37
{
Public partial class Form1: Form
{
SqlConnection conn.
Public _click ()
{
InitializeComponent();
}

Private void button1_Click (object sender, EventArgs e)
{
Try
{
Conn=new SqlConnection (" server=. The database=test3; Uid=sa; The PWD=123456 ");
conn.Open();
SqlCommand CMD=new SqlCommand (" select * from "+ textBox1. Text. The Trim (), conn);
SqlDataReader SQR=CMD. ExecuteReader ();
SQR. Read ();
If (SQR. HasRows)
{
MessageBox. Show (" data in the table has data ");
}
The else
{
MessageBox. Show (" data there is no data in the table ", "prompt", MessageBoxButtons. OK, MessageBoxIcon. Warning).
}
}
The catch (Exception ee)
{
MessageBox. Show (ee. Message);
}
//conn. Close ();

}

Private void button2_Click (object sender, EventArgs e)
{
Conn=new SqlConnection (" server=. The database=test3; Uid=sa; The PWD=123456 ");
SqlCommand CMD=new SqlCommand (" select * from test3 ", conn);
SqlDataAdapter sda=new SqlDataAdapter ();
Sda. SelectCommand=CMD;
The DataSet ds=new DataSet ();
Sda. The Fill (ds, "test3");
DataGridView1. The DataSource=ds. Tables [0];
}
}
}

CodePudding user response:

Select * from test3 test3 this table

CodePudding user response:

Suggest you to debug the code first

CodePudding user response:

Already done, I put the test3 lose wrong, should be Table_3

CodePudding user response:

MessageBox pop up

CodePudding user response:

You can play out

CodePudding user response:

Test3 is the database name, do you want to check the table should be Table_3
  •  Tags:  
  • C #
  • Related