日期:2014-05-17 浏览次数:21065 次
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
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 DatabaseStudy
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void ButtonGetData_Click(object sender, RoutedEventArgs e)
{
string StrConnect = "server = localhost;database = Test;uid = Test;pwd = Nothjkkjjhing/123";
string StrSelect = "select * from [Test].[dbo].[Info]";
SqlConnection conn = new SqlConnection(StrConnect);
//conn.Open();
SqlCommand cmd = new SqlCommand(StrSelect, conn);
SqlDataAdapter ShlyAdapter = new SqlDataAdapter(cmd);
DataSet ShlyDataSet = new DataSet();
ShlyAdapter.Fill(ShlyDataSet);
DataGridShowData.ItemsSource = ShlyDataSet.Tables[0].DefaultView;
}
}
}
DataTable dt =( DataGridShowData.ItemsSource as DataView).Table;
string StrConnect = "server = localhost;database = Test;uid = Test;pwd = Nothjkkjjhing/123";
string StrSelect = "select * from [Test].[dbo].[Info]";
SqlConnection conn = new SqlConnection(StrConnect);
SqlDataAdapter ShlyAdapter = new SqlDataAdapter(cmd);
System.Data.SqlClient.SqlCommandBuilder cb = new System.Data.SqlClient.SqlCommandBuilder(ShlyAdapter);
cb.RefreshSchema();
ShlyAdapter.Update(dt);