I have a ASP:DropDown list which is populated by the following:
public void Fill1()
{
string connectionString = WebConfigurationManager.ConnectionStrings["CRM2Sage"].ConnectionString;
using (SqlConnection _con = new SqlConnection(connectionString))
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Products", _con))
{
I am fairly new to ASP.Net and web programming in general and I am having issues trying to add values from a dropdown list in my gridview to another table.
Here is my scenario. I have 2 tables in my SQL Express DB. When editing the values of table2 in a gridview, I would like to show some data from table1 in a dropdown so users can select a value from table 1 and enter that value in table 2.
I have the Gridview setup to show table2 data.
I created a field template and inserted my dropdown list and linked it to my table1 data source.
When I run my web form, I can click to edit one of the fields in the gridview, and my dropdown list correctly displays the data from table 1, but when I try to update the table2 with the dropdown value, it doesn't correctly update. The row in table2 never updates.
posting the dropdown value from table 1 into the appropriate field in table2..
Again, I am new to this and have been following the tutorials etc on this site, but can't find one pertaining to this topic.
I'm stuck with a problem to populate a DropDownList control with values from the database using item field template in read only mode. since I'm new to ASP.NET. Below is the code and the error I'm getting:
'PictureReadOnlyCategories' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: 'PictureReadOnlyCategories' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value
The code for this is :
<asp:SqlDataSource ID="categoriesDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand ="SELECT [CategoryID], [Name] FROM [Categories] WHERE ([UserId] = @UserId)"> <SelectParameters>
i am using a list view to view, insert, update and delete my data for the admin page this admin page made for the news and we have categories for that so i need to use a drop down list for these categories and when the admin choose on of these categories records its value as an ID to the database.
<asp:QueryStringParameter Name="CategoryID" QueryStringField="ID" /> </SelectParameters> and ([UserId] = @UserId), the dropdown list control will populate values from the database but when i live those 2, it won't populate any value from the database. When i remove the <asp:QueryStringParameter Name="CategoryID" QueryStringField="ID" /> </SelectParameters>,and live ([UserId] = @UserId), i get the error : Must declare the scalar variable "@UserId".
I have a small issue binding the values into a dropdown using LINQ in ASP.NET code-behind.
var clientquer = from i in Entity.New_Bank select i; //var q = (from s in names // select s).Distinct(); // var getlendername = (from db in mortgageentity.New_Lender group db by db.Bank_Name into t select t.Key).ToList(); if (clientquer.Count() > 0) { ddlbankname.DataSource = clientquer.ToList(); ddlbankname.DataValueField = "Bank_ID2"; ddlbankname.DataTextField = "Bank_Name"; ddlbankname.DataBind(); }
It is binding with duplicate values, but I don't want bind duplicate values. I'm trying to solve this by using a group by clause, but it is not working.
How can i load the QuoteNumber database column values into dropdown list which is autogenerated column.I am able to generate the QuoteNumber value and same inserting into database simultaniously all the Quotenumber values should load into dropdown, these two should happen in one click button event.My QuoteNumber dropdown name is "DDQuote" Code for generating Quotenumer and same inserting into database.
Protected Sub btnAQ_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAQ.Click Console.WriteLine(updateRecord("insert into quotes (PartNumber) values ('" + txtPart.Text + "')")) retriveDataToDataGrid() End Sub Function updateRecord(ByVal query As String) As Integer Try Dim connectionString As String = "Database=fabdb;" & "Data Source=localhost;" & "User Id=root;Password=pacvision" Dim rowsEffected As Integer = 0 Dim connection As New MySqlConnection(connectionString) Dim cmd As New MySqlCommand(query, connection) connection.Open() rowsEffected = cmd.ExecuteNonQuery() connection.Close() Return rowsEffected Catch ex As Exception Console.WriteLine(ex.Message) End Try End Function
Ive been strugglng with this one problem for a while now. I have an application as: SelectCommand="SELECT [CategoryID], [Name], [UserId] FROM [Categories] WHERE ([UserId] = @UserId) ORDER BY [Name]"> <SelectParameters> <asp:QueryStringParameter Name="CategoryID" QueryStringField="ID" /> </SelectParameters> [code]....
the dropdown list control will populate values from the database but when i live those 2, it won't populate any value from the database. When i remove only the <asp:QueryStringParameter Name="CategoryID" QueryStringField="ID" /> </SelectParameters> and live ([UserId] = @UserId), i get the error : Must declare the scalar variable "@UserId".
I'm building a small website using ASP.net/C# and I wanted to know how to implement a simple search feature using a text box and a dropdown.
The datasource is a products table and in the text box I enter the product's name and in the dropdown are the categories. (I have managed to populate the dropdown with the available categories already)
It must follow these conditions:
If both text box and dropdown are blank all products must be listed; If a category is chosen all products from that category must be listed; If only text is filled, all products that match are shown;
OleDbException (0x80040e57): The statement has been terminated. String or binary data would be truncated.] System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +745 System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +113
I have Dropdown for Quotenumber(auto increment ).i have created a function to retreive the data from database.data loading into dropdown. when i click on Addquotenumer button the new quotenumber generated and same loading into dropdown but 2 set of Quotenumbers are displaying rather than singleset, i debudded the code the reason was i have called this function twice one is form load and another one in AddQuotenumber button event,both should manadetory as per my requirement. how can un load this dropdown before AddQuotenumber button
Function to retreive data to dropdown Public Sub retriveDataToDropDown() Try Dim connectionString As String = "Database=fabdb;" & "Data Source=localhost;" & "User Id=root;Password=pacvision" Dim query As String = "SELECT QuoteNumber FROM quotes" Dim connection As New MySqlConnection(connectionString) Dim da As New MySqlDataAdapter(query, connection) Dim ds As New DataSet() If da.Fill(ds) Then DDQuote.DataSource = ds.Tables(0) DDQuote.DataTextField = "QuoteNumber" DDQuote.DataBind() 'DDQuote.Items.Insert(0, New ListItem("Select", "Default value")) End If connection.Close() Catch ex As Exception 'Console.WriteLine(ex.Message) End Try End Sub AddquoteNumber button code Protected Sub btnAQ_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAQ.Click Dim connectionString As String = "Database=fabdb;" & "Data Source=localhost;" & "User Id=root;Password=pacvision" Dim rowsEffected As Integer = 0 Dim Query As String = "" Dim connection As New MySqlConnection(connectionString) 'Dim cmd As New MySqlCommand(Query, connection) connection.Open() Query = "insert into Quotes(query follows...................) retriveDataToDropDown() retriveDataToDataGrid() connection.Close() End Sub
I am stuck with an issue. I have around 200 rows in a table with a particular database. I want to copy those values to another table in a different database.
List<string> ls1 = new List<string>(); Now fill in the cycle with some values: while (...){ lst1.Add (value); )
And when I successfully filled the List, as now reads these values, so that I can save the database?I want all values from List, get into the database, a table, how to do it?
I've got a database table with a very large amount of rows. This table represents messages that are logged by a system. Each message has a message type and this is stored it it's own field in the table. I'm writing a website for querying this message log. If I want to search by message type then ideally I would want to have a drop down box listing the message types that have come up in the database. Message types may change over time so I can't hard code the types into the drop down. I'll have to do some sort of lookup. Iterating over the entire table contents to find unique message values is obviously very stupid however being stupid in the database field I'm here asking for a better way. Perhaps a separate lookup table which the database occasionally updates listing just the unique message types that I can populate my drop down from would be a better idea.
The platform I'm using is ASP.NET MVC and SQL Server 2005
I have data entry form like...There are some empty rows and some of them have values. User can Update existing values and can also fill value in empty rows.I need to map these values in my DB table and some of them will be inserted as new rows into the database and existing record will be updated.I need your suggestions, How can I accomplish this scenario with best approach.
I'm having a gridview in my aspx page with checkbox, User can select one or more than one record(s) at a time and clicks on delete button, Then i'm constructing an object of my DTO and adding all the checked row's Primary Key (DataKeyNames - GUID's in case) to a serializable class and generating an XML and sending it as parameter to the Stored Procedure.
My Doubt is, can i bulk delete all the rows from database table those are present in my XML document??
If it works, I can do bulk update with XML only, i already did bulk insertion by generating an XML..
My Another Question is, Will it affect the performance? Each time when i construct an DTO object and adding it to the Generic List??
WHich one is better, I mean ObjectDataSource or SQLDataSource or my XML method?
I want to compare username and password store in database table to the textbox values for that I am using session variable. How to use dataset for session variable?
How to retrive values from database table using dataset?
I Have the gridview control with 2 dropdown list and 2 text boxes,When the textbox chnaged event happen 1 row will create and the dropdown back to initial values( its not retaining the selected values),I am binding the control after text changed method,Is there any properties needs to be set or any other way we can retain the values in postbacks?
To start with - I'm using VS 2008/.NET 3.5 and working in a company-provided template that leaves me restricted to some/many settings that go beyond the body of the page itself. That said, I need to create a page that will display data from individual cells in a database table that, when lined up would look like a normal sentence. Based on certain criteria I would have certain sections of the sentences hide (ex. if it contains a key phrase or if it's empty).
I've seen a method in which Labels could be used to achieve this effect, where I would assign it the grid coordinates of the cell in a table, but I could never get it to work. I've been successfully connected to the table (LINQDataSource) but still have a blank canvas without this fundamental display technique as that will be all that's in it.
I want to name the headers of the ListView control acording to values of the first rows of a table in the database. This I want to do because the number of columns varies for each cutstomer and also the name of the column.
I have a dozen tables, and two dropdown lists.The first drop down list shows the table names. The second dropdown list needs to be poulated with the data from the specific table selected in the first dropdown list.I wrote a stored procedure that will query the selected table name choosen in the the first dropdown list. My results though are only showing this...