Solved

C# html controls

Posted on 2011-03-11
11
268 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
  • 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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 500 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to read json value 2 49
Connection String 16 60
What is "public object" in C#? 3 47
Getting error in connectionstring with Excel. 30 32
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 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