Home > Back-end >  C # database connection problem
C # database connection problem

Time:09-18

C # the great god help me to look at what went wrong



The main page

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Using System. Windows;
Using System. Windows. Controls;
Using System. Windows. The Data;
Using System. Windows. The Documents;
Using System. Windows. Input;
Using System. Windows. Media;
Using System. Windows. Media. Imaging;
Using System. Windows. Navigation;
Using System. Windows. Shapes;

The namespace _15_1
{
///
///MainWindow. Xaml interaction logic
///

Public partial class MainWindow: Window
{
Public MainWindow ()
{
InitializeComponent ();
}


Private void btnSelect_Click (object sender, RoutedEventArgs e)
{
Select the s=new select ();
S.S how ();
This. Hide ();



}
}
}


Deputy page

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Using System. Windows;
Using System. Windows. Controls;
Using System. Windows. The Data;
Using System. Windows. The Documents;
Using System. Windows. Input;
Using System. Windows. Media;
Using System. Windows. Media. Imaging;
Using System. Windows. Shapes;
Using System. The Data. SqlClient.
Using System. The Data;
The namespace _15_1
{
///
///select xaml interaction logic
///

Public partial class select: Window
{
The public select ()
{
InitializeComponent ();
}

Private void Window_Closing_1 (object sender, System.Com ponentModel CancelEventArgs e)
{
MainWindow mv=new MainWindow ();
Mv. The Show ();
This. Hide ();
}
SqlConnection conn.
SqlDataAdapter sda.
The DataSet ds;
Private void btnSelect_Click (object sender, RoutedEventArgs e)
{
Conn=new SqlConnection (" server=. The database=student19; Uid=sa; The PWD=123456 ");
String sname=txtName. Text;
Sda=new SqlDataAdapter (" select id as the serial number, the name as the name, the age as age, sex as gender from the info where name='" + sname + "' ", conn);
Ds=new DataSet ();
Sda. The Fill (ds); -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- will card in a few seconds after each run, and then suggests that there is an error, untreated SqlException
Dgshow. ItemsSource=ds. Tables [0]. DefaultView;

Dgshow. Columns [0]. Width=60;
Dgshow. Columns [1]. The Width=60;
Dgshow. Columns [2]. Width=60;
Dgshow. Columns [3]. The Width=60;

Ds. The Dispose ();
Sda. The Dispose ();
Conn. The Dispose ();

}
}

CodePudding user response:

The SQL statement is wrong
, it is in Chinese

CodePudding user response:

Problem has been solved, thank you very much, I sent yet another question, should you have time I answer it
  • Related