DataSource Controls :: Writing Data To A Table Using Sql Command Object?
Feb 23, 2010Having serious trouble inserting data into my db... i am able to select and display data just not write it to the database..
[Code]....
Having serious trouble inserting data into my db... i am able to select and display data just not write it to the database..
[Code]....
I have a table that is not getting updated. My insert command is working fine. Here is the update code from business logic area and stored prodecure. The SP works fine when I execute it from sql mgmt studio and updates the table:
[Code]....
I don't understand how the stored procedure is returning false. It's supposed to continue looping and continue writing rows. Right now it writes the very first row, and then it goes into the If Not AdvanceLinkBanned.Add(banrec) Then and it goes in here, prints the message and exits the sub. Why is it thinking the add returns false? If Not AdvanceLinkBanned.Add(banrec) ? Doesn't this return the id of the new record? Isn't this not zero? Zero would make it false. How can this be false? Isn't it supposed to return the next record created ? Doesn't SELECT SCOPE_IDENTITY() return the value of the record id? How do I test this?
[Code]....
I have tried to query a table with an xml column by using XQuery and I can't get the Select to work.
All my knowledge/understanding of the subject comes from this MSDN article:
[URL]
so I am probably overlooking something minor:
I tried this query Select col1, Phone.Query('element CellPhone {I am not sure about what goes here} I tried {data('Phone/cellPhone} from aTable Where Phone.Exist('/Phone/cellPhone/text()[contains.,"412-8977"]') = 1 This syntax is definitely not fun.
I'm using vwd 2008 express
I need to display a single field from an sqlserver table, do I need to use sqlDataSource ect. or is there a simpler way (like msaccess's LookUp) for single values.
I want to issue an INSERT command for an SQL Server table using DataAdapter without first issuing a SELECT command. Could anybody send me lines of code to handle this? Also how do i manage INSERT into selective table columns (I have 10 columns but i only want to update 2 of them)?
View 2 RepliesI was just wondering that when we insert some datainto database we can use the following method.
create a sql datasourse ,
set the conection string,
set the insert comand type,
set insert parameters,
and Set the SQL Statement like
sqldatasource.insertStatement="insert into tablename(field1, field2) values(@parameter1, @parameter2)";
and then call the datasourse insert() function,
this method is usually used for single line insertion at the end of the DB.
Now I am a starter in asp.net c#,
I want to know that if There is a way that I have lots of data like some XML file that have the same table structure as the SQL database table
and I want to write that data to the database, HOw to do it Properly,
I can Still achieve the required results by iterating through XML datarows and for each row conecting to db and inserting and then disconecting dfrom the db,
But I want to know that if there is a way to do it in one go meaning I have to conect to database only one time,
Note: I already have some data in my SQL table, there are three fields(ID Name and Nickname) the ID(primary key) is INT type and auto incremented, the name and nickname are strigns.
the xml file has the structure
<userdata>
<user>
<name>michel</name>
<nickname>micho</nickname>
</user>
</userdata>
I'm using vb and after i converted it from C# and tried to implement this:
[Code]....
I got an error that said: Unable to cast object of type 'System.Web.UI.WebControls.GridView' to type 'System.Web.UI.WebControls.LinkButton'.
And here's my code for the gridview table.
[Code]....
I've tried altering the code here and there but it never work
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
i have gridview i added it select command field i want when it is clicked,the id of the table displayed in label and i have update command field but the problem the update can't update the primary key i want when it is clicked update all the record
View 7 Repliesi had a requirement for dynamic sorting so i wanted to assign order by.. dynamically depending on what column is clicked for sorting
i tried to modify the sql data source command
in ds selecting event by using
e.command.CommandText=modifiedCommandHere; but it doesnt work as it always picks up selectCommand specified in aspx page
I have a problem and I could not solve it. Hope you can write a sample code for me. I have a Microsoft Access database, and in asp.net website, i draw a grid view on the design page. I also configure the source data access. It works, but display all the data in the database. i want to display all the data which is related to John. sql = "select username, customer_name, phone from db where username = John" how do i configure the data grid view?
View 3 RepliesI am using VS 2008.I am building a datatable of records to be inserted into a SQL Server 2005 table.
The program loops through this table and builds a SqlParameter for each DataColumn in the datatable. The SqlParameters are used in the SQL Insert statement.
The field I am having a problem with is of type 'bit' in the database table and has no default value and cannot be nulls. The field is called 'Active' The meaning of this field in the application is Boolean i.e True or False. When inserting the record, I wish to default the field to "False".
When I define the columns in the datatable I am forced to use the following code to build the datatcolumn containing the boolean field i.e. dtcActive.DataType = GetType(Boolean) as there is no GetType(Bit)
Dim dtcActive As New DataColumn("Active")
dtcActive.DataType = GetType(Boolean)
dtcActive.Unique = False
dtcActive.AllowDBNull = False
dtcActive.DefaultValue = False
dtProviderDayDetails.Columns.Add(dtcActive)
However, when I build the SqlParameter I am forced to use this:
If field.ColumnName = "Active" Then
prm.SqlDbType = SqlDbType.Bit
prm.Value = "False"
End If
This is because there is no SqlDbType.Boolean. The problem I have is there is no value I have been able to give the SqlParameter that is accepted by the Insert statement. It complains that the boolean field cannot be null on Insert.
I'm using the asp.net membership on my website. On the User Administration page i've got a GridView to show the details of the users on the site. As a datasource rather than just using the Membership.GetAllUsers function i've got a SQLDataSource as i need to display user information from 3 different tables. I'm trying to add a delete button to the GridView. I'm setting the Membership's UserName as a DataKey and then using the RowDeleting event to call Membership.DeleteUser for the appropriate UserName. This works fine and the user is deleted however i then get an error showing up that "Deleting is not supported by data source 'SqlDataSource1' unless DeleteCommand is specified."
I don't want to use the SqlDataSource for deleting as i've already done it using the Membership. How can i stop it from trying to do this? Here is the cut-down that i have if you're interested. The selectcommand in the sqldatasource was auto-generated by it.
[Code]....
i'm trying to issue a select command in my app soi could execute the command and retrive the data into a string variable.the problem is that this command is overloaded with DataSourceSelectArgument and i can't figure out what it is.i'm using sql server express and when issue a n insert command for example sq.Insert(); i have no problems.this the command that's holding me:
SqlDataSource sq = new SqlDataSource();
sq.ConnectionString = ConfigurationManager.ConnectionStrings["CustomerDatabaseConnectionString1"].ToString();
sq.SelectCommandType = SqlDataSourceCommandType.Text;
sq.SelectCommand = "SELECT * FROM CustomerTable where customerID = 1";
string result = sq.Select(some overload that's stopping me);
Basically i deal with two tables.i have a table T1 of the following format:id company_name i need to read this data and create a table T2 as followsi wrote the following code. it worked fine for retrieving data and modification but fails to insert the modified data into the 2nd table.the error is, it does not recognise the value for @token
ArrayList dynarr=new ArrayList(); // global variable
protected void Button2_Click(object sender, EventArgs e)
{
int row = 1; int i;
string strcmd = null;
string Connection = "Data Source=....";
SqlConnection conn = new SqlConnection(Connection);
string str = "select company_name from T1 where ID=@ID";
[code]...
This is the first time I have been working on databases and I am trying to insert data using an object datasource but no data is being inserted and no exception is thrown. I'm not sure where I am going to wrong. I am putting user data into session variables and inserting the session variables into the dataacess class layer and have a try and exception but nothing being thrown. Any help would be really appreciated because I don't know even where to start looking with this or how I can get the error to be thrown. Please see some of my code below to give an idea of what I am doing
Object Access Class
public void InsertCarPolicyHolder(PolicyHolderClass ph, CarInsuranceOptions options)
{
[code]...
I am facing the following problem when i try to add record in database. "System.Data.SqlClient.SqlException: A severe error occurred on the current command.The results, if any, should be discarded." This exception occurs occasionally, and the sql server log shows the following error whenever the above exception occurs:
Server,Unknown,A user request from the session with SPID 54 generated a fatal exception. SQL Server is terminating this session. Contact Product Support Services with the dump produced in the log directory.
May you tell me how can I transfer data from a table to another table, the condition of non-repetition rows
as a procedure in database MS QSL server 2005 ,Works in the first day of the month I use the first table in the prodation environment it is contain the employee data and the second to update first table only
Traditionally with an Object Data Source, the wired up class will have its public properties available for binding (i.e. Gridview columns, etc.) which works well. But what if one of my wired up business objects has a property that is an object itself; can I drill down to a property on that object property and still use it?
So in additiona to the traditional:MyBusniessObject.OrderID...I want to use:MyBusniessObject.Customer.NameID
Your 1st response might be to just wire up the 'Customer' class, but I need properties both on 'MyBusinessObject'and 'Customer'. I do not think this can be done, as the ODS will not display properties on an object instance property. I have tried manually typing in the drilled down value as well, but that wasn't a success either.
I am creating an insert statement in my c# code to insert records to an access database table. I am getting the error copied below using c# code. When I copy the generated insert statement from the console and run this on my access database, it succesfully appends a record in the table.Insert statement generated:
insert into [Pet Fish-log 2010] ([Specimen Type], Year, [Lab Number], [Last Name], [First Name], [Middle Initial], Gender, [Date of Birth], [Collection Date], [Date Received], Client, [Tissue Type], [Block Number],
[code]......
i have a "Users today" function that i am trying to work on, i have all the tables set up, and a TimeStamp column, i would like to know how i could get all the users that appeared, but for that day only.
So i used the select statement, but then when i tried to add into query, filtering, i tried using the DateTime.Now, but it only got the users specific to that date, hour, and second.
I have two tables in oracle ,
i want to update two table data in a single command...
I use the DetailsView control to display selected employee's data for HR. The list of data elements has gotten pretty long so I thought I'd put some tables & panels inside the ItemTemplate and EditTemplate. Testing with NO code behind in effect works perfectly on display & update. Now I need to manipulate some stuff in the code behind which requires me to cast the controls I'm after. However old cast code doesn't work (it says the row index doesn't exist).
First is a clip of the DetailsView which gives me 3 nice columns.
[Code]....
I have a checkbox column in a Gridview that I would like to use to insert the value of one cell in the row into an access database. There will be a maximun of five cells allowed to be selected so there can be one value written to one field in the database up to the maximum of the five fields. The access database has five columns: Selection1 ,Selection2, Selection3 ,Selection4 and Selection5
When the checkbox is checked, the value of one cell (PliD) should be written to each field in the database. Ie: checkbox in row 1 should write PliD value to Selection1, checkbox in row 2 should write PliD value to Selection2, checkbox in row 3 should write PliD value to Selection3 and on depending on which checkbox has been checked. I am not sure how to get the value of the checkbox and write it into the corresponding fields in the database.
[Code]....
Im building on a transaction website that gives the user a few choices for them to choose when they want to view their transactions history
They can choose:
1.Current Month
2. Last 1 month and current month
3. Last 2 month and current month
4. Select date range
How do I include this variable in the stored procedure?