标题: 很疑惑,照着老师的写代码还是插入不了 [打印本页] 作者: 王连 时间: 2012-4-20 23:18 标题: 很疑惑,照着老师的写代码还是插入不了 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("插入成功");
}
}