c# 大神們幫我看看到底哪出了錯

main頁
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.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace _15_1
{
/// <summary>
/// MainWindow.xaml 的互動邏輯
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void btnSelect_Click(object sender, RoutedEventArgs e)
{
select s = new select();
s.Show();
this.Hide();
}
}
}
副頁
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.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;
namespace _15_1
{
/// <summary>
/// select.xaml 的互動邏輯
/// </summary>
public partial class select : Window
{
public select()
{
InitializeComponent();
}
private void Window_Closing_1(object sender, System.ComponentModel.CancelEventArgs e)
{
MainWindow mv = new MainWindow();
mv.Show();
this.Hide();
}
SqlConnection conn;
SqlDataAdapter sda;
DataSet ds;
private void btnSelect_Click(object sender, RoutedEventArgs e)
{
conn = new SqlConnection("server=.;database=student19;uid=sa;pwd=123456");
string sname = txtName.Text;
sda = new SqlDataAdapter("select id as 序號,name as 姓名,age as 年齡,sex as 性別 from info where name='"+sname+"'",conn);
ds = new DataSet();
sda.Fill(ds); --------------------------------------------每次運行后都會卡幾秒,然后提示這有錯誤,未處理SqlException
dgshow.ItemsSource=ds.Tables[0].DefaultView;
dgshow.Columns[0].Width=60;
dgshow.Columns[1].Width=60;
dgshow.Columns[2].Width=60;
dgshow.Columns[3].Width=60;
ds.Dispose();
sda.Dispose();
conn.Dispose();
}
}
uj5u.com熱心網友回復:
SQL陳述句錯了,是中文的
uj5u.com熱心網友回復:
問題已解決,十分感謝,我又發了另一個問題,如有時間懇請解答一下轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/49251.html
標籤:C語言
上一篇:求用c#設計
