TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ivan
NA
22
0
data not being saved? newbie here :)
Jan 1 2010 7:20 PM
I am quite confused as to why my data is not being saved.
I have a form that allows the user to fill out their information. When the user clicks on the Save button, the program does everything except save the data into the database.
Anyone know why this would happen and what I should be looking for?
Below is what the action for my "Save" button
[code] private void btnSave_Click(object sender, EventArgs e)
{
DialogResult result;
result = MessageBox.Show("Are you sure you want to save your changes?", "Save Changes?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
_user.insertUser();
MessageBox.Show("New User Saved!");
//Not hiding correctly after data is saved.
frmNewUser close = new frmNewUser();
close.Hide();
}[/code]
Below is code that my "Save" button calls.
[code] public void insertUser()
{
cmdInsert.Parameters["@FirstName"].Value = _firstName;
cmdInsert.Parameters["@LastName"].Value = _lastName;
con.Open();
int rowsAffected;
rowsAffected = cmdInsert.ExecuteNonQuery();
con.Close();
}[/code]
I am just trying it out with only Firstname and lastname for now.
I have declared what I need to:
[code] private int _userID = 0;
private string _firstName = "";
private string _lastName = "";
[/code]
and
[code]public int UserID
{
get { return _userID; }
set { _userID = value; }
}
public string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}
public string LastName
{
get { return _lastName; }
set { _lastName = value; }
}
[/code]
Yes, I have believe I have set up everything for my cmdInsert:
[code]INSERT INTO Users
(FirstName, LastName)
VALUES ([@FirstName], [@LastName])[/code]
and I have the Parameters set up for @FirstName and @LastName respectively.
almost forgot, I also have this inserted in my form too:
[code]private Users _user = new Users();[/code]
Can anyone see what I am doing wrong here? The program connects to the database, it just doesnt save anything. It adds a new line, but doesnt save any information.
Thanks,
Ivan
Reply
Answers (
9
)
Lost all items in MenuStrip and statusStrip
menu in .net mobile application