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
Yosra Chourou
NA
8
756
Insert records by user who's connected Winforms
Jul 8 2016 5:51 AM
I have a form (F1) where user will provide their respective credentials username and password . After a sucessfull login , the controls moves to the Client Form (F2) and display welcome username in a label on it.
Client Form contains:
labels and textboxes(name, address, function , ...)
Button Insert
DataGridView bind to DB (name, address, function ,..,
UserId)
Now , I want to insert a Client
After filling textboxes, I want to add a Client a show it added by user who's connected.
Ex: if I logged with Username Rose after that add a client, in my datagridView , show me my row of insert added by Rose.
Here is my code of Insert:
private
void
button1_Click(
object
sender, EventArgs e)
{
if
( comboBox2.SelectedValue !=
null
&& textBox1.Text !=
string
.Empty && textBox2.Text !=
string
.Empty && textBox4.Text !=
string
.Empty)
{
string
cmdStr =
"Insert into Client (idUser,name,address,function,telephone,commentaire)values (@idUser,@name,@,address,@function,@telephone,@commentaire)"
;
SqlConnection con =
new
SqlConnection(
"Data Source=User-PC\\SQLEXPRESS;Initial Catalog=timar;Integrated Security=True"
);
SqlCommand cmd =
new
SqlCommand(cmdStr, con);
con.Open();
//The problem in this code how Can I get the id of username,
Error cannot convert string Rose to int.
cmd.Parameters.AddWithValue(
"@idUser"
,label.Text);
cmd.Parameters.AddWithValue(
"@name"
, (comboBox2.SelectedValue));
cmd.Parameters.AddWithValue(
"@,address"
, textBox1.Text);
cmd.Parameters.AddWithValue(
"@function"
, textBox2.Text);
cmd.Parameters.AddWithValue(
"@telephone"
, textBox4.Text);
cmd.Parameters.AddWithValue(
"@commentaire"
,txtArchive.Text);
int
LA = cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show(
"Le Client a été ajouter avec succés !"
,
"Saisie Rendez-vous"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
DisplayData();
ClearData();
}
else
{
MessageBox.Show(
"Vérifier que tous les champs sont remplis !"
,
"Erreur"
,MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
I am not able to figure out how to do this, i am very new to c# and trying to learn.
Thanks in Advance .
Reply
Answers (
6
)
oops concept for all Definition
code of sending notification