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
Israel
701
1.3k
217.2k
Code with specific condition
Aug 16 2019 9:05 AM
Hi,
I would like to resolve a logic. Little bit complicated for my.
I have four Textboxes (TextBox1, TextBox2, TextBox3, TexBox4) and three Buttons (Button1, button2, Button3).
What I need to do?
If TextBox1 and TextBox2 or TextBox1 and TextBox3 are filled by number more than 0 or minus 0 then click at Button3 (for example do Button3.PerformClick()). Otherwise don't activate Button3 and read the code above to save to my Database.
private
void
Button1_Click(
object
sender, EventArgs e)
{
////////////////////////////////////////////////////////////////////
// The condition should be here. Its should pass ONLY these TextBoxes when are not filled
//////////////////////////////////////////////////////////////////
if
(conn.State != ConnectionState.Open)
conn.Open();
SqlCommand comm1 =
new
SqlCommand();
comm1.Connection = conn;
SqlParameter data =
new
SqlParameter(
"@date"
, SqlDbType.Date);
SqlParameter nord =
new
SqlParameter(
"@number"
, SqlDbType.VarChar);
SqlParameter contas =
new
SqlParameter(
"@name"
, SqlDbType.VarChar);
comm1.Parameters.Add(date);
comm1.Parameters.Add(number);
comm1.Parameters.Add(name);
date.Value = TextBox1.Text;
number.Value = TextBox2.Text;
name.Value = TextBox3.Text;
comm1.Connection = conn;
comm1.CommandText =
"insert into Table ([date],[number],[name])values(@date,@number,@name)"
;
{
if
(MessageBox.Show(
"Are you sure to save?"
,
"Saving window"
, MessageBoxButtons.YesNo) == DialogResult.Yes)
{
try
{
comm1.ExecuteNonQuery();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText =
"select [date],[number],[name] from Table"
;
DataTable dt =
new
DataTable();
SqlDataAdapter da =
new
SqlDataAdapter(cmd);
da.Fill(dt);
dgvTest.DataSource = dt;
}
finally
{
dgvTest.CurrentCell = dgvTest.Rows[dgvTest.Rows.Count - 2].Cells[0];
}
Reply
Answers (
9
)
offline quiz application using C# with sql
Facing an error while i'm get record