Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C# html controls

Posted on 2011-03-11
11
Medium Priority
?
283 Views
Last Modified: 2012-08-14
I want to use my drop down selected value and text box in an update statement.  So that my new query will be
"update gp_timesheetload  set "mydropdown value" = "textbox value"
based on my where_clause string




void ClickHandler(object sender, EventArgs e)
    {
 update statement goes here    
     }


string where_clause = "where company= '" + company_1 + "'and filename ='" + bach_1 + "' and weekending = '" + week_1 + "' and project='" + proj_1 + "'";
SqlCommand cmd = new SqlCommand("seLECT  distinct costcat from gp_timesheetload " + where_clause, cn);
cn.Open();
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
rdr.Read();

<select name="weekending" style="font-size:8pt" tabindex="1" >
<%
        while (rdr.Read())
        {
 %>       
             <option><%=rdr[0].ToString()%></option><br><br><br><br>
<%            
        }

    }  
    
  
%>
</select>


<asp:TextBox id="tb1" runat="server" />
<asp:Button id="Button1" onclick="ClickHandler" runat="server" Text="Click here to submit"></asp:Button>

Open in new window

0
Comment
Question by:jaypappas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 35114495
Try this code.
You need to use ExecuteNonQuery() to execute an update statement
I understood that you need to update selected Dropdownlist value and TextBox value into separate columns in the table.
string connetionString = null;
SqlConnection cnn ;
SqlCommand cmd ;
string sql = null;

connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password";
sql = "update gp_timesheetload  set dropdowncolumn = '" + myDropdown.SelectedValue + "', textboxColumn = '" + myTextBox.Text + "'";

cnn = new SqlConnection(connetionString);
try
{
    cnn.Open();
    cmd = new SqlCommand(sql, cnn);
    cmd.ExecuteNonQuery();
    cmd.Dispose();
    cnn.Close();
    MessageBox.Show (" ExecuteNonQuery in SqlCommand executed !!");
}
catch (Exception ex)
{
    MessageBox.Show("Can not open connection ! ");
}

Open in new window


Raj
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 35114501
One more important thing.
You need to add WHERE condition also to the update statement. Otherwise it will update all the columns

Update the SQL Query line with your WHERE condition.
sql = "update gp_timesheetload  
set dropdowncolumn = '" + myDropdown.SelectedValue + "', 
textboxColumn = '" + myTextBox.Text + "' 
WHERE somecolumn = somevalue";

Open in new window


Note:- If required, backup your database before trying update statement.

Raj
0
 

Author Comment

by:jaypappas
ID: 35114503
How do I get the texbox and drop down value
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 35114570
You mean read TextBox value and Dropdownlist value to SQL Query.

That's what I shown in my previous SQLQuery attached - Is it not working ?

Raj
0
 

Author Comment

by:jaypappas
ID: 35116262
My control is called weekending and set dropdowncolumn = '" + myDropdown.SelectedValue + "', is not working.  This is really my main problem.  And I need to do this on the function below

void ClickHandler(object sender, EventArgs e)
    {
 update statement goes here    
     }

Open in new window

0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 35116787
I think you are not clear about previous comment.

The code I posted before - http:#a35114495 - put it this event
Also remember to replace the sample table name and column names I gave with your actual ones

Read once more my previous comments are let me know
Raj
0
 

Author Comment

by:jaypappas
ID: 35117383
where are you references weekending.  I dont see that nowhere.  I dont know how to get the value on the click event.  I am not sure you are clear on what I am asking.
0
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 2000 total points
ID: 35117405
That's what I said - replace the control names that I used with your real control name

For eg: If 'weekending' is the dropdownlist name, replace 'myDropdown' in my code with 'weekending'

Raj
0
 

Author Comment

by:jaypappas
ID: 35117642
I did replace and it dont work
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 35119887
When you debug any error ?

Raj
0
 

Author Comment

by:jaypappas
ID: 35155992
Raj I think it did not work because I was using html control without runat = "server".  I was trying to mix asp and asp.net.  But what u gave me worked when I changed to pure asp.net controls
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question