.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Post New Web Links

Inserting Selected Row onto SQL Server Database from GridView

Posted By:      Posted Date: October 26, 2010    Points: 0   Category :ASP.Net
 



protected void Authorise(object sender, EventArgs e)
        {
            CheckBox chk;

            foreach (GridViewRow rowItem in GridView1.Rows)
            {
               // gets the Debit Reference number for each row checked
                string type = GridView1.DataKeys[rowItem.RowIndex].Values[0].ToString();
				// gets the Debit Error Type Number number for each row checked
                string DDIREF = GridView1.DataKeys[rowItem.RowIndex].Values[1].ToString();
 
                chk = (CheckBox)(rowItem.Cells[0].FindControl("RowChecker"));
   
                // chk.checked will access the checkbox state on button click event
                if (chk.Checked)
                {
                  
					 if (type == "1")
					 {
						// Message_ltr.Text = type + DDIREF;
						 string[] posList;
						 //   string a = "false";
						 DataTable dt = this.ExcelToDatatable_dt;

						 posList = positionList;
						 foreach (DataRow row in dt.Rows)
						 {
								 string error = "No Error Message";
								 fn.InsertNewDDIsTemporary_Proc(
										  row["DDIREF"].ToString()                    //  String DDIREF_P
										, row["Sortcode"].ToString()                  //  String Sortcode_P
										, row["AccountNo"].ToString()     


View Complete Post


More Related Resource Links

Inserting Selected Row onto SQL Server Database from GridView

  




protected void Authorise(object sender, EventArgs e)
        {
            CheckBox chk;

            foreach (GridViewRow rowItem in GridView1.Rows)
            {
               // gets the Debit Reference number for each row checked
                string type = GridView1.DataKeys[rowItem.RowIndex].Values[0].ToString();
				// gets the Debit Error Type Number number for each row checked
                string DDIREF = GridView1.DataKeys[rowItem.RowIndex].Values[1].ToString();
 
                chk = (CheckBox)(rowItem.Cells[0].FindControl("RowChecker"));
   
                // chk.checked will access the checkbox state on button click event
                if (chk.Checked)
                {
                  
					 if (type == "1")
					 {
						// Message_ltr.Text = type + DDIREF;
						 string[] posList;
						 //   string a = "false";
						 DataTable dt = this.ExcelToDatatable_dt;

						 posList = positionList;
						 foreach (DataRow row in dt.Rows)
						 {
								 string error = "No Error Message";
								 fn.InsertNewDDIsTemporary_Proc(
										  row["DDIREF"].ToString()                    //  String DDIREF_P
										, row["Sortcode"].ToString()                  //  String Sortcode_P
										, row["AccountNo"].ToString(

an issue with server while inserting data into database

  

hi there

I am having an issue while inserting some data into (database )sqlserver,i have provide you with error detailed ,I think is quit basic issue but i do not how to sort it out, please help me out on this ,many thanks

 

error

System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
   at System.Data.Sql

MS SQL Server: Disconnect Users From Database - Kill User Session

  
If you ever wanted to restore your database from a SQL backup file (.bak), but there are still users connected to your database, the backup operation will fail causing the error: Exclusive access could not be obtained because the database is in use.

Inserting new row in GridView in ASP.NET 2.0

  
The GridView was not designed to insert new rows, but there is a way to accomplish this with very little code. This article shows how to do that. The GridView was not designed to insert new rows, but there is a way to accomplish this with very little code.

Publishing SQL Server Database using Publishing Wizard : Tips & Tricks

  
We can use SQL Server Publishing Wizard to deploy our local Database to remote hosting server/production server.This feature is available in SQL Server 2008/VWD 2008.

Below is the complete step by step guide of this process.

Adding Rows in GridView without using a Database

  
This article describes on how to add rows in GridView without using a database. Basically the GridView will be populated with data based on the values entered in the TextBox on Button Click and retain the GridView data on post back.

Adding Multiple Columns and Rows in GridView without using a Database

  
This article describes on how to add multiple columns and rows in GridView without using a database. Basically the GridView will be populated with data based on the values entered in each TextBoxes on Button Click and retain the GridView data on post back.

Connestion string create any database server

  
This links important to how to create connection string to any data base sever.

SQL Server Database Transaction

  
A transaction is a group of SQL commands executed together as a single component of work to be accomplished. If all of these commands succeed, then a transaction is committed - the changes to the data are made final. If any of the commands within a transaction fail, then the entire transaction is cancelled, or in SQL Server terms, the transaction will be rolled back.

Transactions are one of the things that keep your data safe, but they're not necessarily easy to understand. Here's some help:

Gridview that exports selected rows to Excel

  
his seems like a messy workaround, but I ended up using two Gridviews - one to display my data and show my checkboxes, and the other which was invisible amd would eventually end up as my Excel spreadsheet.

Sorting Data in a GridView Web Server Control

  
The GridView control provides built-in sorting functionality without requiring any coding. You can further customize the sort functionality of the GridView control by using custom SortExpression property values for columns as well as by using the Sorting and Sorted events

Database Export Wizard for ASP.net and SQL Server

  
A step wizard for ASP.net to export database objects to CSV, TXT, HTML, XML, or SQL. it guides users through a few simple steps to choose a database object (table, view, or query), select columns, and export the data in any of the standard formats CSV, HTML, XML, or SQL.

How to let user edit selected gridview columns, not entire row

  

Hello!-

I've got a gridview I would like to let the user edit a couple of columns.  Seems like everything I'm coming across so far makes the entire row editable.  

Hopefully the solution isn't too complicated.  Can someone point me in the right direction?

 


Connecting to MS SQL Server database using webmatrix.

  

Hi,

I am novice  user to raizor syntax using webmatrix and i am trying to connect MS Sql server database (instead of using .sdf file i am using .mdf file) using the tool webmatrix for startersite.

The connection string that i setup as follows.

<?xml version="1.0"?>

<configuration>

    <system.web>
        <compilation debug="false" targetFramework="4.0" />
    </system.web>
    <connectionStrings>
    <add name="OESConnectionString" connectionString="Data Source=.\SQLServer2005;AttachDbFilename=|DataDirectory|\OES_Data.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
    </connectionStrings>

</configuration>

And i am using websecurity helper as well and the setup is as follows.

WebSecurity.InitializeDatabaseConnection("Data Source=INLTE5556\\SQLServer2005;Initial Catalog=OES;Integrated Security=True", "System.Data.SqlClient", "UserProfile", "UserId", "Email", true);

When i am trying to insert the user details into database i am getting the below error.

Format of t

Rendering data with HTML tags in the DD Gridview for a selected column

  

I am having trouble finding out where and how to HTML Encode a cell's data on the Dynamic Data (v4.0) gridview of List.aspx.  As a simple case, suppose I have formatted cell data that is A<br/>B in the DB.    Obviously, I want A stacked on B in the cell.

It seems gridView1.HtmlEncode = true has gone away.

So maybe I'll try to catch it on the RowDataBound event:

protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)

        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                // Html Encode the cells
            }

        }

but this event never fires?


Has anyone figured out how to properly render HTML tags data in the List.aspx's GridView1? 

If I figure this out, then I can add a MetaAttribute called something like [EncodeAsHtml(true)] and be on my way.  Thanks!


LINQ to SQL - Validating if item is in Database, but if item is not items not inserting into databas

  

Hello,

I am new to this, so bear with me.  I am writing an application in C# that uses LINQ to validate a datacontext off a textbox to see if the record exists already.  If the record does exist I inserted an if statement to advise the user that the record exists, if the record does not exist I would like to allow the record to be added to the database.  If I take out my else statement everything works fine as far as inserting goes, but I do not want to allow inserts in this scenario.  I have tried moving the if and else statement to different parts of the code but can't quite figure this one out.  Any help would be apprecaited, attached is the code.  This code is set to a button press.  As a matter of fact, if you see any other errors along the way please feel free to point them out. 

Thanks,

Pete

    protected void enterBTN_Click(object sender, EventArgs e)
    {
        //make new data context

        SHCDataContext insNewAll = new SHCDataContext();
 
        //LINQ to check if customer exists in database
        var checkExisting = from c in insNewAll.Customers
                            where c.custLastName.Contains(custLastNameTB.Text.ToString())
                            select c.custLastName;
        //make list to store values
        L

sql server 2008 adventureworks database

  

dear Friends


For my MCTS 70 -433 examination, I recently installed sql server 2008 and installed the sample databases too. but my issue is, in that book they have mentioned a database called "AdventureWorks2008" and the nice thing is I don't have a such a database with me in my sql server 2008. 


And the query is 

-- MERGE Statement
USE AdventureWorks2008
MERGE INTO	Sales.SalesOrderDetailHistory AS SODH
USING Sales.SalesOrderDetail AS SOD
ON SODH.SalesOrderID = SOD.SalesOrderID
AND SODH.SalesOrderDetailID = SOD.SalesOrderDetailID
WHEN NOT MATCHED BY TARGET THEN
INSERT (LineTotal, SalesOrderID, SalesOrderDetailID, CarrierTrackingNumber, OrderQty
, ProductID, SpecialOfferID, UnitPrice, UnitPriceDiscount
, rowguid, ModifiedDate, Cancelled)
VALUES(LineTotal, SalesOrderID, SalesOrderDetailID, CarrierTrackingNumber, OrderQty
, ProductID, SpecialOfferID, UnitPrice, UnitPriceDiscount
, rowguid, ModifiedDate, DEFAULT)
WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET SOHD.Cancelled = 'True'
OUTPUT $action , inserted.* ;	


Please help me to overcome this issue and let me know where can I download that database too.


Thanking you

happy Coding


Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend