Click here to Skip to main content
15,890,579 members
Home / Discussions / C#
   

C#

 
GeneralRe: I found some issues in coding but I don't know how to solve them. Could you give me some advices ? Pin
patrickjiang258026-Mar-15 22:49
patrickjiang258026-Mar-15 22:49 
GeneralRe: I found some issues in coding but I don't know how to solve them. Could you give me some advices ? Pin
Afzaal Ahmad Zeeshan26-Mar-15 22:51
professionalAfzaal Ahmad Zeeshan26-Mar-15 22:51 
GeneralRe: I found some issues in coding but I don't know how to solve them. Could you give me some advices ? Pin
patrickjiang258026-Mar-15 22:58
patrickjiang258026-Mar-15 22:58 
GeneralRe: I found some issues in coding but I don't know how to solve them. Could you give me some advices ? Pin
F-ES Sitecore27-Mar-15 0:41
professionalF-ES Sitecore27-Mar-15 0:41 
GeneralRe: I found some issues in coding but I don't know how to solve them. Could you give me some advices ? Pin
patrickjiang258027-Mar-15 4:37
patrickjiang258027-Mar-15 4:37 
GeneralRe: I found some issues in coding but I don't know how to solve them. Could you give me some advices ? Pin
F-ES Sitecore27-Mar-15 4:54
professionalF-ES Sitecore27-Mar-15 4:54 
GeneralRe: I found some issues in coding but I don't know how to solve them. Could you give me some advices ? Pin
patrickjiang258027-Mar-15 5:02
patrickjiang258027-Mar-15 5:02 
SuggestionRe: I found some issues in coding but I don't know how to solve them. Could you give me some advices ? Pin
Richard Deeming27-Mar-15 2:34
mveRichard Deeming27-Mar-15 2:34 
You might want to take a look at Dapper[^], which is used on the StackExchange family of sites. Since your SQL column names seem to match the property names on your UserModel class, it should be fairly simple to use:
C#
private IDbConnection CreateConnection()
{
    return new SqlConnection("YOUR CONNECTION STRING HERE");
}

public IEnumerable<UserModel> SelectAllUser()
{
    const string sql = @"SELECT [UserID], [Password], [Name], [Sex], [Phone]," 
        + "[Tutor], [DptName], [College], [University]," 
        + "[Major], [EnrollYear], [Cntnt] " 
        + "FROM [TrainingExam].[dbo].[ExprmntUser]"; 
    
    using (var connection = CreateConnection())
    {
        return connection.Query<UserModel>(sql);
    }
}

public int InsertUser(UserModel user)
{
    const string sql = @"INSERT INTO [TrainingExam].[dbo].[ExprmntUser] VALUES ("
        + "@UserID, @Pass, @Name, @Sex, @Phone, @Tutor, @DptName, @College, @University, @Major, @EnrollYear, @Content)";
    
    using (var connection = CreateConnection())
    {
        return connection.Execute(sql, user);
    }
}

public int DeleteUser(UserModel user)
{
    const string sql = @"DELETE FROM [TrainingExam].[dbo].[ExprmntUser] WHERE UserID = @UserID";
    
    using (var connection = CreateConnection())
    {
        return connection.Execute(sql, user);
    }
}

public int UpdateUser(UserModel user)
{
    const string sql = @"UPDATE [TrainingExam].[dbo].[ExprmntUser] SET UserID = @UserID, Name = @Name, Sex = @Sex, Phone = @Phone, EnrollYear = @EnrollYear, " 
        + "Tutor = @Tutor, Major = @Major, DptName = @DptName, College = @College, University = @University, Content = @Content " 
        + "WHERE UserID = @UserID";
    
    using (var connection = CreateConnection())
    {
        return connection.Execute(sql, user);
    }
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: I found some issues in coding but I don't know how to solve them. Could you give me some advices ? Pin
patrickjiang258027-Mar-15 4:44
patrickjiang258027-Mar-15 4:44 
GeneralRe: I found some issues in coding but I don't know how to solve them. Could you give me some advices ? Pin
patrickjiang258027-Mar-15 4:50
patrickjiang258027-Mar-15 4:50 
GeneralRe: I found some issues in coding but I don't know how to solve them. Could you give me some advices ? Pin
Richard Deeming27-Mar-15 4:59
mveRichard Deeming27-Mar-15 4:59 
GeneralRe: I found some issues in coding but I don't know how to solve them. Could you give me some advices ? Pin
patrickjiang258027-Mar-15 5:20
patrickjiang258027-Mar-15 5:20 
QuestionThe usage of Unsigned types Pin
GerVenson26-Mar-15 5:36
professionalGerVenson26-Mar-15 5:36 
GeneralRe: The usage of Unsigned types Pin
PIEBALDconsult26-Mar-15 5:52
mvePIEBALDconsult26-Mar-15 5:52 
AnswerRe: The usage of Unsigned types PinPopular
Richard Deeming26-Mar-15 6:02
mveRichard Deeming26-Mar-15 6:02 
AnswerRe: The usage of Unsigned types Pin
OriginalGriff26-Mar-15 6:05
mveOriginalGriff26-Mar-15 6:05 
AnswerRe: The usage of Unsigned types Pin
Sascha Lefèvre26-Mar-15 6:09
professionalSascha Lefèvre26-Mar-15 6:09 
GeneralRe: The usage of Unsigned types Pin
harold aptroot26-Mar-15 22:41
harold aptroot26-Mar-15 22:41 
GeneralRe: The usage of Unsigned types Pin
GerVenson26-Mar-15 23:40
professionalGerVenson26-Mar-15 23:40 
GeneralRe: The usage of Unsigned types Pin
harold aptroot26-Mar-15 23:45
harold aptroot26-Mar-15 23:45 
AnswerRe: The usage of Unsigned types Pin
den2k8826-Mar-15 22:55
professionalden2k8826-Mar-15 22:55 
AnswerRe: The usage of Unsigned types Pin
jschell27-Mar-15 11:15
jschell27-Mar-15 11:15 
QuestionCombobox and "autocompletion" Pin
TMattC26-Mar-15 0:18
TMattC26-Mar-15 0:18 
AnswerRe: Combobox and "autocompletion" Pin
TMattC26-Mar-15 0:23
TMattC26-Mar-15 0:23 
AnswerRe: Combobox and "autocompletion" Pin
Simon_Whale26-Mar-15 1:29
Simon_Whale26-Mar-15 1:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.