C# 带有插入数据的动画文本

C# 带有插入数据的动画文本,c#,sql-server,wpf,C#,Sql Server,Wpf,我正在尝试将数据插入数据库(WPF)。这是我的连接代码: 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.Docu

我正在尝试将数据插入数据库(
WPF
)。这是我的连接代码:

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;
using System.Data.SqlClient;
using System.Data.Sql;
namespace sba1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        SqlConnection sc = new SqlConnection("Data Source=ASUS\\SQL;Initial Catalog=test;Integrated Security=True");
        SqlCommand cmd;
        public MainWindow()
        {
            InitializeComponent();
        }


        private void btn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                sc.Open();

                cmd = new SqlCommand("insert into prsn(id,name) values ('" + txtid + "' , '" + txtname + "')", sc);
                cmd.ExecuteNonQuery();
                MessageBox.Show("update sucsessful to database");
                sc.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

    }
}

有人能解释一下吗?

您应该使用
TextBox
Text
属性,比如:

txtname.Text
顺便说一句,你应该经常使用。这种类型的字符串连接对攻击是开放的

txtname.Text