using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace 第一个
{
class Program
{
static void Main(string[] args)
{
string DataDir = AppDomain.CurrentDomain.BaseDirectory;
if (DataDir.EndsWith(@"\bin\Debug\")
|| DataDir.EndsWith(@"\bin\Release\"))
{
DataDir = System.IO.Directory.GetParent(DataDir).Parent.Parent.FullName;
AppDomain.CurrentDomain.SetData("DtaDirectory", DataDir);
}
Console.WriteLine("请输入您要插入的用户名:");
string userName = Console.ReadLine();
Console.WriteLine("请输入您要插入的密码:");
string passWord = Console.ReadLine();
using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;
AttachDBFilename=|DataDirectory|\Database1.mdf;integrated Security=true;User instance=True"))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "insert into T_Userss(UserName,PassWord) values('"+userName+"','"+passWord+"')";
cmd.ExecuteNonQuery();
Console.WriteLine("插入成功");
}
}
Console.WriteLine("打开数据库连接成功");
Console.ReadKey();
}
}
}
这是通过VS插入到SQL的信息的代码,看过视频的同学都知道,但是我不知道为什么我插入不进去呢?求教高手。。 |