1 Console.Write("请输入要修改的编号:");
2 string ucode = Console.ReadLine();
3 SqlConnection conn = new SqlConnection("server=.;database=Data0504;user=sa;pwd=123;");
4 SqlCommand cmd = conn.CreateCommand();
5
6 cmd.CommandText = "select *from Users where Ucode=@a";
7 cmd.Parameters.Clear();
8 cmd.Parameters.AddWithValue("@a", ucode);
9
10 conn.Open();
11 SqlDataReader dr = cmd.ExecuteReader();
12 bool hh=false;
13
14 if (dr.HasRows)
15 {
16 hh = true;
17 }
18 conn.Close();
19
20 if (hh)
21 {
22
23 string username = "";
24 while (true)
25 {
26 Console.Write("请输入用户名:");
27 string str = Console.ReadLine();
28 try
29 {
30 username = Convert.ToString(str);
31 if (username == "")
32 {
33 Console.Write("名字不能为空,请重新输入:");
34 }
35 else
36 {
37 break;
38 }
39
40 }
41 catch
42 {
43 break;
44 }
45 }
46 string nickname = "";
47 while (true)
48 {
49 Console.Write("请输入昵称:");
50 string str = Console.ReadLine();
51 try
52 {
53 nickname = Convert.ToString(str);
54 if (nickname == "")
55 {
56 Console.Write("名字不能为空,请重新输入:");
57 }
58 else
59 {
60 break;
61 }
62
63 }
64 catch
65 {
66 break;
67 }
68 }
69 string password = "";
70 while (true)
71 {
72 Console.Write("请输入密码:");
73 string str = Console.ReadLine();
74 try
75 {
76 password = Convert.ToString(str);
77 if (password.Length >= 4)
78 {
79 break;
80 }
81 else
82 {
83 Console.Write("请重新输入至少四位的密码:");
84 }
85
86 }
87 catch
88 {
89 break;
90 }
91 }
92
93 string sex = "";
94 while (true)
95 {
96 Console.Write("请输入性别:");
97
98 sex = Console.ReadLine();
99 try
100 {
101
102 if (sex == "男")
103 {
104 Convert.ToBoolean(sex = "True");
105 break;
106 }
107 else if (sex == "女")
108 {
109 Convert.ToBoolean(sex = "False");
110 }
111 else
112 {
113 Console.Write("请输入男女:");
114 }
115
116 }
117 catch
118 {
119 break;
120 }
121 }
122
123 DateTime birthday = new DateTime();
124 while (true)
125 {
126
127 try
128 {
129
130 Console.Write("请输入生日:");
131 birthday = Convert.ToDateTime(Console.ReadLine());
132 break;
133
134 }
135 catch
136 {
137 Console.Write("请输入正确的日期格式:");
138 }
139 }
140
141 Console.Write("请输入民族:");
142 string nation = Console.ReadLine();
143 conn.Open();
144 cmd.CommandText = "update Users set UserName=@b, PassWord=@c,NickName=@d, Sex=@e, Birthday=@f, Nation=@g where Ucode=@a";
145 cmd.Parameters.Clear();
146 cmd.Parameters.AddWithValue("@a", ucode);
147 cmd.Parameters.AddWithValue("@b", username);
148 cmd.Parameters.AddWithValue("@c", password);
149 cmd.Parameters.AddWithValue("@d", nickname);
150 cmd.Parameters.AddWithValue("@e", sex);
151 cmd.Parameters.AddWithValue("@f", birthday);
152 cmd.Parameters.AddWithValue("@g", nation);
153
154 int count = cmd.ExecuteNonQuery();
155 conn.Close();
156
157 if (count > 0)
158 {
159 Console.WriteLine("修改成功!");
160 }
161 else
162 {
163 Console.WriteLine("修改失败!");
164 }
165 }
166 else
167 {
168
169 Console.WriteLine("未查到此编号数据,请确定编号是否正确!");
170 }