Web Forms :: Don't Allow To Insert More Than 2 Items In Database
Mar 14, 2013
I have 2 table in data base
1-HOuse_info Table
2-House_p Table
in House_p table save users Product information and in House_info table save Users Information
In both Tables is column that name is BehcodeN
I want if users in BehcodeN save this text='free' 'they can't insert product morethan 2 number and if they want insert their third product It show error that You can't insert morethan 2 product below are my code
In Product.aspx page I have button that when users click on it they can insert their product
 protected void ImageButton2_Click1(object sender, ImageClickEventArgs e)
{
string data = Server.UrlDecode(Request.QueryString["BehCode"]);
string price = RadioButton2.Checked ? TextBox1.Text : "null";
SqlCommand _cmd = new SqlCommand("insertproduct3", _cn);
[Code] ....
and SP
USE [behtop]
GO
/****** Object: StoredProcedure [dbo].[insertproduct3] Script Date: 03/14/2013 17:42:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[insertproduct3]
[Code] ....
ok here I can insert 2 product succesfully. but when I want insert third produt it makes below error instead of showing error message
Server Error in '/behtop website' Application.
Object cannot be cast from DBNull to other types.
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.InvalidCastException: Object cannot be cast from DBNull to other types.Source Error:Â
Line 805: _cmd.Parameters.AddWithValue("@behcode", data);
Line 806: _cmd.Parameters.AddWithValue("@id", Convert.ToInt32(ViewState["Id"]));
Line 807: int ID = Convert.ToInt32(_cmd.ExecuteScalar()); Line 808: if (ID > 0)
Line 809: {
why this happen?
View 1 Replies
Similar Messages:
Feb 9, 2011
i have added several items into a list box, but i m not sure how to insert the several items within the list box individually into the database..
for example,
- within my list box, i have apple, orange and banana.
- next, i would like to insert into database in different row -->
fruit name
apple
orange
banana
View 4 Replies
Jan 18, 2011
I'm trying to populate 1000 ListItems in a ListBox.
how to do it. Currently only 100 items are being displayed even though I set the capacity of the ListBox to 1000.
Below is sort of how my code looks like. :)
listBox.Items.Capacity = 1000;
foreach(entity ent in enitityCollection)
{
ListItem listItem = new ListItem();
listItem.Value = ent.Id.ToString();
listItem.Text = ent.Name;
listBox.Items.Add(listItem);
}
entityCollection has 989 records in it.
Code does not generate any error. only that at the end of the loop I only get 100 items mapped to my ListBox.
Is this how the ListBox is designed for?
View 3 Replies
Oct 19, 2010
I have grid view in ASP.Net 3.5. I need to add multiple blank rows in a gridview and then have to save them in database. How can I do that in most simplest way?
View 7 Replies
Nov 29, 2010
what I am trying to do is: insert multiple selected items from CheckBoxList into DB
I tried using (foreach) as:
foreach (ListItem item in bookingid.Items)
{
if (item.Selected == true)
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString))
{
con.Open();
SqlCommand cmd2 = new SqlCommand("") }}}
But it only adds the first selected item .. What Should i do ?
View 7 Replies
May 8, 2010
I have two ListBoxes. I can move items from one list box to the other. I have an Insertcommand for inserting added values from the "ActivePrograms" list box to a db.
my problem is that it inserts only one item when sometimes the user added multiple items.
how do I insert all existing items from "ActivePrograms" list box?:
second issue: how do I make sure the insert command go through the list of items in the listbox and makes sure these rows does mot already exsited in the db? in other words insert only NEW values for that 'Id' value
[Code]....
View 8 Replies
Jan 27, 2011
i defined an enum with the [flags] attribute and binded it to a checkboxlist.
my question is how can i insert the selected items to a list?
this is my code:
[Code]....
View 4 Replies
May 20, 2010
I have a DDL bound to a sqlDataSource, and I want to insert an item in the first position. I tried using this code in the onDatabound event:
Protected Sub ddl_onDataBound(ByVal sender As Object, ByVal e As EventArgs) Handles ddl.DataBound
ddl.Items.Insert(0, "None")
End Sub
But when I load the page, the item "None" is inserted twice at the beginning of the DDL? So I see something like:
None
None
item1
item2
Do I need to put the items.insert somewhere else, like on the pageLoad, to avoid it being executed twice, or am I doing something really wrong?
View 9 Replies
Aug 10, 2011
I am trying to create a add all button to execute a query and insert all rows from a gridview.
Can't make it work, it only inserts one row.
vb Code:
Imports System.Data.SqlClient Public Class page1 Â
Inherits System.Web.UI.Page  Â
Protected Sub Page_Load(ByVal sender As Object,
ByVal e As System.EventArgs) Handles Me.Load   End Sub  Â
[Code]....
View 3 Replies
Aug 20, 2010
i need to insert multiple rows at a time into database table(sqlserver) from datatable or gridview. Actually iam looping through the rows of gridview and inserting each row. Is there any method to insert entire table of rows at a time into database table. Both datatable columns and database table coulmns are similar.
View 2 Replies
Feb 8, 2011
Here is my code which insert listbox items table and create record.
protected void Button1_Click(object sender, EventArgs e)
{
ListItem li = new ListItem();
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source= C:Ruchitaweb" + @"WebSite527afcergonomic.mdb";
conn.Open();
for (int i = 0; i < ListBox1.Items.Count; i++)
{
li.Text = ListBox1.Items[i].Text;
}
OleDbCommand cmd = new OleDbCommand("insert into record(recorditem) values('" + li.Text + "')", conn);
cmd.ExecuteNonQuery();
conn.Close();
}
this is inserting in diffrent rows but i want this in one row with (,)so i can parse it and get it back which items user selected. and i also want to show messge box that show the record number.
View 5 Replies
Dec 20, 2010
I wonder if there is a simple way to insert a new ListItem between 2 existing items of a dropdownlist?
View 3 Replies
May 15, 2010
I want give some space between the items of the dropdownlist. is it possible?
ddl:
item1
item2
item3
View 3 Replies
Jan 4, 2010
I have a dropdownlist, which dynamically populate data from SQL Server and i wanna manually insert two items on top of the DDL after data binding. So, the DDL would has data something like this:
Select Branch (manually insert)
ALL (manually insert)
AIR
AMP
ABG
...
I tried to achieve it by using code below:
ddlBranch.Items.Insert(0, "Select Branch")
ddlBranch.Items(0).Value = CMM.sExcVal1
ddlBranch.Items.Insert(1, "ALL")
ddlBranch.Items(1).Value = "ALL"
but it comes out giving me the data like this:
Select Branch (manually insert)
ALL (manually insert)
('AIR' branch should be here but it's gone)
AMP
ABG
...
After manually insert the 'ALL' item into the DDL, the 'AIR' is gone which is already replaced by the 'ALL'. How can i remain all the data from server and at the same time i can manually insert two items?
View 3 Replies
Feb 9, 2010
I am building a web site, it's used to manage the data in SQL server so the another web site(connect to the same SQL database) can receive the new infoSo far I've build 2 parts, one manages the news system, the another manages the album system, news manage system work perfect, when I update, add or delete news form the web site (using sqldatasource, INSERT, DELETE and UPDATE command), the data inside SQL changes as well.
View 2 Replies
Jun 1, 2010
in my button4 click event, i want to insert checboxlist items to data table. first i want to delete all of the exisiting and then insert again.
my code is below but it is not working if you could explain anyone ?
in page load I have written code so that existing checkbox items are selected.
[code]...
View 5 Replies
Nov 24, 2013
I've 2 listboxes i want to transfer items from listbox1 to listbox2 and then save the items on listbox2 (transfered items) on database.
View 1 Replies
May 7, 2015
I have a DropDownList shows the company names and a ListBox shows the products of the company I selected in the DropDownList and I can select many products from ListBox:
in sql I have these tables:
1.company: comp_id,comp_name
2.product: prod_id,prod_name
3.Pro_Comp_details:Pro_Comp_ID,Pro_ID,Comp_ID (bridge table)
In .net I have a page with a button to add to bridge table to add a company and many products to it
this is my code but there is something missing
protected void btn_save_add_Click(object sender, EventArgs e) {
poc.Pro_Comp_ID = Convert.ToInt32(txt_prod_of_compID_add.Text);
int id1 = Convert.ToInt32(String.Format("select Comp_ID from Company where Comp_Name = '{0}'", ddl_choose_companyName.SelectedValue));
int[] id2 = new int[ListBox1.Items.Count];
[Code] ...
View 1 Replies
May 7, 2015
how can i add multiple row to Listview with texbox outside the listview before saving it to database.
View 1 Replies
Jun 16, 2010
I have stored checkbox items in the database where Yes = "1" and No = "0".
If I want to retrieve them again (from database) as checkbox items on a page, how do I go about this?
View 1 Replies
Feb 28, 2011
I am returning records from the database and I need to compare those records against my checklist box to determine which ones should be checked.
Query is working properly and returning 3 records.
Vehicle ID = 40, Option ID = 1
VehicleID = 40, Option ID = 36
VehicleID = 40, Option ID = 37
[Code]....
This is not working, can anyone point me in the right direction???
View 7 Replies
Nov 25, 2010
I have menu list like this
and I want to fill it's Items from my SQL database, is that possible ?
View 3 Replies
Jun 29, 2010
i have created menus using menucontrol (populated using database) its showing me menu items properly.now menu items goes out of screen (viewing area of the screen)i want to wrap that menu items means if the menu items goes out of the screen it will automatically shows the remaining menu items to the next line... and i have taken menucontrol in span tag..
View 2 Replies
Jun 24, 2010
I would like to display the following information for each "Camera" (in the format below) on my web page in an HTML table. All the data is contained in one table in my database:
For Camera = Canon (e.g.):
Type (Text via asp:Label)
Lens Size (Text via asp:Label)
Storage (Text via asp:Label)
Max. video resolution (Text via asp:Label)
Max. photo resolution (Text via asp:Label)
Weight (Text via asp:Label)
Dimensions (Text via asp:Label)
Sensor (Text via asp:Label)
...where (Text) is the value retrieved from the database for the given Camera. advise on the best way to retrieve this data? The only method I can think of (from my limited experience!) is to have a separate VB function for each value, to run separate SELECT queries for each field, and then to set the (Text via asp:Label)
value accordingly. I am already doing this for datagrid retrieves etc. For example:[Code]....
BUT... I know there must be a better method for the above requirement!
View 9 Replies
Dec 21, 2011
I want to display all the items existing in database for ex:
If i enter just book. All the items with book work should get displayed
Example in google search as soon as we enter one word related all things get displayed. I am not talking about auto completion
View 1 Replies