public bool Insert(UserInfo obj) { var da = new SqlDbDataAccess(); SqlCommand cmd = da.GetCommand("INSERT INTO [dbo].[Userinfo] ([uname],[pass]) VALUES (@uname, @pass)"); var p1 = new SqlParameter("@uname", SqlDbType.VarChar, 50) {Value = obj.Uname}; var p2 = new SqlParameter("@pass", SqlDbType.VarChar, 50) {Value = obj.Pass}; cmd.Parameters.Add(p1); cmd.Parameters.Add(p2); cmd.Connection.Open(); int val = cmd.ExecuteNonQuery(); cmd.Connection.Close(); return val > 0; }
private List<UserInfo> GetData(SqlCommand cmd) { cmd.Connection.Open(); SqlDataReader reader = cmd.ExecuteReader(); var list = new List<UserInfo>(); while (reader.Read()) { var obj = new UserInfo { Uname = reader.GetString(0), Pass = reader.GetString(1), type = reader.GetInt32(2) }; list.Add(obj); } reader.Close(); cmd.Connection.Close(); return list; }