Select Command Lost Thus Gridview Shows Nothing

Nov 17, 2006

Hi there,
I am not sure how many of you have experienced this problem before but here is how to replicate it:
 
Add a GridView, SqlDataSource and Button to a new project
Set the DataSourceID to the SqlDataSource object
Set AllowPaging to True on the GridView
Within the Button1_Click sub, change the SqlDataSource.SelectCommand to a new Query e.g SELECT * FROM table WHERE ID > 1
Run the project 
Click on another page, i.e. "3" on the GridView
 
SqlDataSource.SelectCommand is now blank(!), thus Gridview displays nothing.
 
Has anyone else found a solution to this annoying issue? 
 
Any help is appreciated.

Regards 
 
 

 

View 5 Replies


ADVERTISEMENT

Stored Procedure Passes Test In Gridview, But Nothing Shows Up On The Page

Feb 25, 2008

Like the subject says I have tested the SP in Gridview. Everything looks fine. But when run nothing shows up on the page.
I have tried using QueryStrings to pass the data and Controls.
Here is the Gridview Code:<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"
CellPadding="4" DataSourceID="SqlDataSource1">
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<RowStyle BackColor="White" ForeColor="#003399" />
<Columns><asp:BoundField DataField="FirstName" HeaderText="FirstName"
SortExpression="FirstName" /><asp:BoundField DataField="LastName" HeaderText="LastName"
SortExpression="LastName" /><asp:BoundField DataField="EthnicID" HeaderText="EthnicID"
SortExpression="EthnicID" /><asp:BoundField DataField="Gender" HeaderText="Gender"
SortExpression="Gender" /><asp:BoundField DataField="Height" HeaderText="Height"
SortExpression="Height" /><asp:BoundField DataField="Weight" HeaderText="Weight"
SortExpression="Weight" />
<asp:BoundField DataField="Hair" HeaderText="Hair" SortExpression="Hair" />
<asp:BoundField DataField="Eyes" HeaderText="Eyes" SortExpression="Eyes" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
</Columns>
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
</asp:GridView>
 
 
Here is the Datasource:<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SQL2005_311004_modelsystemConnectionString %>"
SelectCommand="spSearch" SelectCommandType="StoredProcedure">
<SelectParameters><asp:QueryStringParameter DefaultValue="" Name="FirstName"
QueryStringField="fn" Type="String" />
<asp:QueryStringParameter Name="LastName" QueryStringField="ln" Type="String" />
<asp:Parameter Name="EthnicID" Type="String" />
<asp:Parameter Name="Gender" Type="String" />
<asp:Parameter Name="Height" Type="String" />
<asp:Parameter Name="weight" Type="String" />
<asp:Parameter Name="Hair" Type="String" />
<asp:Parameter Name="Eyes" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="State" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
 
I hope you can help me with this one!!!

View 2 Replies View Related

Data Lost After INSERT Command

Dec 21, 2006

I have a website that is used to enter dates from a calendar. For example, user A might go to the website and select 20 different days in January. When user A clicks on the Save button the dates are written to the database with an INSERT command. This works fine. However, when user B then goes through the same procedure, say selecting 5 dates that are in the set selected by user A, those dates are properly saved in the database but the rows containing user A's same 5 dates disappear. I suspect this is something simple but I'm new and ignorant. Please help.

View 4 Replies View Related

SQL 2012 :: Agent Job History Shows Step Still Running But Shows Start And End Times?

Jul 1, 2015

I have a SQL Agent job that runs at 4:15 in the morning. The job has 5 steps, each step only runs if the preceding step succeeds. The second step, which calls an SSIS package that does the main processing, appears to finish as it goes on to the next step; however, when looking in 'View History' there are 2 entries for this step - the first one shows it as still running (Circled Green Arrow) but with a start and end time. The second entry says the job succeeded.

I have been seeing conflicts, such as deadlocks, with later jobs. I suspect this job is causing the conflicts - maybe the package is still running in the background instead of having actually completed?

what conditions a job step my be showing in the job history as both running AND completed successfully?

View 6 Replies View Related

Defining Command,commandtype And Connectionstring For SELECT Command Is Not Similar To INSERT And UPDATE

Feb 23, 2007

i am using visual web developer 2005 and SQL 2005 with VB as the code behindi am using INSERT command like this        Dim test As New SqlDataSource()        test.ConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").ToString()        test.InsertCommandType = SqlDataSourceCommandType.Text        test.InsertCommand = "INSERT INTO try (roll,name, age, email) VALUES (@roll,@name, @age, @email) "                  test.InsertParameters.Add("roll", TextBox1.Text)        test.InsertParameters.Add("name", TextBox2.Text)        test.InsertParameters.Add("age", TextBox3.Text)        test.InsertParameters.Add("email", TextBox4.Text)        test.Insert() i am using UPDATE command like this        Dim test As New SqlDataSource()        test.ConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnectionString").ToString()        test.UpdateCommandType = SqlDataSourceCommandType.Text        test.UpdateCommand = "UPDATE try SET name = '" + myname + "' , age = '" + myage + "' , email = '" + myemail + "' WHERE roll                                                         123 "        test.Update()but i have to use the SELECT command like this which is completely different from INSERT and  UPDATE commands   Dim tblData As New Data.DataTable()         Dim conn As New Data.SqlClient.SqlConnection("Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|Database.mdf;Integrated                                                                                Security=True;User Instance=True")   Dim Command As New Data.SqlClient.SqlCommand("SELECT * FROM try WHERE age = '100' ", conn)   Dim da As New Data.SqlClient.SqlDataAdapter(Command)   da.Fill(tblData)   conn.Close()                   TextBox4.Text = tblData.Rows(1).Item("name").ToString()        TextBox5.Text = tblData.Rows(1).Item("age").ToString()        TextBox6.Text = tblData.Rows(1).Item("email").ToString()       for INSERT and UPDATE commands defining the command,commandtype and connectionstring is samebut for the SELECT command it is completely different. why ?can i define the command,commandtype and connectionstring for SELECT command similar to INSERT and UPDATE ?if its possible how to do ?please help me

View 2 Replies View Related

Reporting Services :: Report Parameter Shows (Select A Value) Only For First Selection

Jun 11, 2015

I have a rdl where its working fine while report preview, for parameter  it shows <Select a value> only first select . for next select its just showing dropdown list of values .

How can i get <select a value> for all selections. I referred few links which says only for first select you will get <select a value> ,from second select it just shows dropdown.

If we want <select a value> again then we should go back design part and then preview again. But I don't want. What is the possible way to see <select a value> for every select without going back to design.

View 3 Replies View Related

Select Parameters With Gridview

Aug 2, 2007

I have a form that has 4 fields to fill in. I have a button that can add these fields to a sql database. I also want to put a button next to the "add" button so you can fill out the same fields and search for those values. Here's what i have so far. I want to select based on the fields, but i'm having trouble with the syntax of the parameters. I also want to add something, so if nothing is filled out in one of those boxes, it retuns back all records for the default value.
  string strConnection = ConfigurationManager.ConnectionStrings["TimeAccountingConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(strConnection);

String selectCmd = "SELECT * FROM users WHERE firstname = @firstame or lastname = @lastname or office = @office or team = @team";
SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd, myConnection);

myCommand.SelectCommand.Parameters.Add(new SqlParameter("@firstname", SqlDbType.VarChar, 50));

myCommand.SelectCommand.Parameters.Add("@firstname", txtFirstName.Text);
myCommand.Parameters.AddWithValue("@lastname", txtLastName.Text);
myCommand.Parameters.AddWithValue("@team", dwnTeam.Text);
myCommand.Parameters.AddWithValue("@office", dwnOffice.Text);

DataSet ds = new DataSet();
myCommand.Fill(ds, "users");

MyDataGrid.DataSource = ds.Tables["users"].DefaultView;
MyDataGrid.DataBind(); 

View 5 Replies View Related

Select Just A Couple Of Rows Into Gridview

May 7, 2008

 I am using a sqlDataSource to read my query and to put the rows into a gridview. Now I want to read just a couple of rows from my query based on a maximum number, also defined in the table. I have absolutely no idea how to do that..for example: I want to view  only the 10 most recent subsciptions into my gridview. The subscriptions are stored into tabel Subscriptions which has values id, userid,date. Table Event has a parameter "maximum subscriptions" (which is 10 in my example) I hope it is clear enough?Thank you in advance!BlueiVeinz 

View 2 Replies View Related

Changing The SQLDatasource SELECT For A Gridview

May 19, 2008

I cant seen to change the Select command for a SQL Datasourcetry #1            SqlDataSourceProfilesThatMatch.SelectCommand = strSQLForSearch            SqlDataSourceProfilesThatMatch.SelectParameters("ProfileID").DefaultValue = pProfileID            SqlDataSourceProfilesThatMatch.SelectParameters("LoggedInUsersZipcode").DefaultValue = pUsersZipCode            SqlDataSourceProfilesThatMatch.SelectParameters("ZipDistance").DefaultValue = pDistance
            NewProfilesThatMatchGridView.DataBind()
try #2            SqlDataSourceProfilesToBeMatched.SelectParameters.Clear()            SqlDataSourceProfilesThatMatch.SelectCommand = strSQLForSearch            SqlDataSourceProfilesThatMatch.SelectParameters.Add("ProfileID", pProfileID)            SqlDataSourceProfilesThatMatch.SelectParameters.Add("LoggedInUsersZipcode", pUsersZipCode)            SqlDataSourceProfilesThatMatch.SelectParameters.Add("ZipDistance", pDistance)
            NewProfilesThatMatchGridView.DataBind()
No errors but no rows show in the gridview. If I debug and get the value strSQLForSearch and paste it into a new SQL query window I get results.
Any ideas????
Thanks
 

View 3 Replies View Related

Sqldatasource, Does It Select If Not Bound To A Gridview, Formview On The Page?

Feb 22, 2008

Using 3.5
If I have a sqldatasource on the page, is it run if it is not bound to a data object like a gridview?
Seems like if i want to access the data (like set a label text) from the sqldatasource I have to use code to first create a dataview then pick throught it. This seems like I'm running it twice. I'm new at .net so I dont know how to tell.
I don't want to write data select code programatically when I can just through an SDS on the page, but wondered it it ran just because it's on the page.

View 2 Replies View Related

Need Gridview To Display Different Columns Based On New SELECT Statement

Apr 23, 2008

I have built an Advanced Search page which allows users to select which columns to return (via checkbox) and to enter search criteria for any of the selected columns (into textboxes). I build the SQL statement from the properties of the controls. Works great.
My problem is getting my gridview control to play nicely. At first I used a SqlDataReader and bound the gridview to it, thus giving me the ability to run new SQL statements through it (with different columns each time). Worked nicely. But, per Microsoft, sorting can only be done if the gridview is bound to a datasource control like the SqlDataSource. So I wrote the code to handle sorting. No big deal; worked nicely. But I could not adjust the column widths programmatically unless bound to a datasource control like the SqlDataSource. And could not figure out a work around.
So, I decided to use the SqlDataSource. Works great. Except, I cannot figure out how to run a new SELECT statement through the SQLDataSource and have the gridview respond accordingly. If I try to return anything other than the exact same columns defined declaratively in the html, it pukes. But I need to be able to return a new selection of columns each time. For example, first time through the user selects columns 1,2,3,4 – the gridview should show those 4 columns. The second time the user selects columns 2,5,7 – the gridview should those 3 columns (and ONLY those 3 columns). Plus support selection and sorting.
I am desperate on this. I've burned 2.5 days researching and testing.  Does anyone have any suggestions?
Thanks,
Brad

View 9 Replies View Related

Gridview Select Statement With User.identity.name In The Where Clause

May 5, 2008

Hello everyone,
I have a view, NAS_vPosition that has a coloumn vLogin_Acting and I want to use the user.identity.name to select the row from this table that matches.
So far i have tried:
SelectCommand = "Select * FROM NAS_vPosition WHERE vLogin_Acting = ' <%=User.Identity.Name %> ' "
with no success.
Any help is appreciated

View 6 Replies View Related

[ask] How To Append String To The Previous Select Statement Bounded To Gridview

Jun 4, 2007

i have a case : i'm using a select statement with SqlCommand and save the results in the SQLDataAdapterand using the data table I post the result to the gridview and show it there....my question is what should I do to append string to the SQL Command?? 

View 2 Replies View Related

Want Error Message To Appear When No Database Results Were Returned In GridView, Also Other GridView Issues.

Jun 12, 2008

Hi, I am seeking a hopefully easy solution to spit back an error message when a user receives no results from a SQL server db with no results. My code looks like this What is in bold is the relevant subroutine for this problem I'm having.   Partial Class collegedb_Default Inherits System.Web.UI.Page Protected Sub submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submit.Click SqlDataSource1.SelectCommand = "SELECT * FROM [college_db] WHERE [name] like '%" & textbox1.Text & "%'" SqlDataSource1.DataBind() If (SqlDataSource1 = System.DBNull) Then no_match.Text = "Your search returned no results, try looking manually." End If End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load SqlDataSource1.SelectCommand = "SELECT * FROM [college_db] ORDER BY [name]" SqlDataSource1.DataBind() End Sub Protected Sub reset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles reset.Click SqlDataSource1.SelectCommand = "SELECT * FROM [college_db] ORDER BY [name]" SqlDataSource1.DataBind() End SubEnd Class  I'm probably doing this completely wrong, I'm a .net newb. Any help would be appreciated. Basically I have GridView spitting out info from a db upon Page Load, but i also have a search bar above that. The search function works, but when it returns nothing, I want an error message to be displayed. I have a label setup called "no_match" but I'm getting compiler errors. Also, next to the submit button, I also have another button (Protected sub reset) that I was hoping to be able to return all results back on the page, similar to if a user is just loading the page fresh. I'd think that my logic would be OK, by just repeating the source code from page_load, but that doens't work.The button just does nothing. One final question, unrelated. After I set this default.aspx page up, sorting by number on the bottom of gridview, ie. 1,2,3,4, etc, worked fine. But now that paging feature, as long with the sorting headers, don't work! I do notice on the status bar in the browser, that I receive an error that says, "error on page...and it referers to javascript:_doPostBack('GridView1, etc etc)...I have no clue why this happened. Any help would be appreciated, thanks! 

View 2 Replies View Related

GridView Based On SQLServerDataSource Using A Select Union Statement, Impacts On Update And Insert?

Jan 3, 2006

I have a GridView dispalying from a SQLServerDataSource that is using a SQL Select Union statement (like the following):

SELECT    FirstName,    LastNameFROM    MasterUNION ALLSELECT    FirstName,    LastNameFROM    CustomORDER BY    LastName,    FirstName
I am wondering how to create Update and Insert statements for this SQLServerDataSource since the select is actually driving from two different tables (Master and Custom).  Any ideas if or how this can be done?  Specifically, I want the Custom table to be editable, but not the Master table.  Any examples or ideas would be very much appreciated!
Thanks,
Randy

View 5 Replies View Related

Select Command

Oct 9, 2006

I'm using the following Select Command:SELECT MAX(Document) AS DOC FROM dbo.Communicator WHERE (ReleaseDate <= { fn NOW() })It shows the most current date in the ReleaseDate column - even if the date is in the future. I don't want it to show future dates. If I change the command to WHERE (ReleaseDate >= { fn NOW() }) it doesn't work at all. I only want it to return one row - the latest releases date that is equal to or less than now.Any ideas?

View 3 Replies View Related

SQL Select Command

May 29, 2007

I have a web form that has textbox1, textbox2 and DropDownList1.  Let’s say textbox one is first name, textbox2 is last name and dropdownlist1 is age. How do I write a query that will select from database table dbo.emoployee where last name = dbo.employee.lastname and all other fields are blank, I want it to return all employees with that last name. If someone types in the last name and selects the age from the drop down list then I want to return all employees where last name = dbo.employee.lastname and age = dbo.employee.age. If someone types in just the first name then I want to return all employees where first name = pub.employees.firstname? I have been trying to do this using the SQLDatasource but cannot seem to figure it out.

View 5 Replies View Related

SQL Select Command

May 29, 2007

I have a web form that has textbox1, textbox2 and DropDownList1.  Let’s say textbox one is first name, textbox2 is last name and dropdownlist1 is age. How do I write a query that will select from database table dbo.emoployee where last name = dbo.employee.lastname and all other fields are blank, I want it to return all employees with that last name. If someone types in the last name and selects the age from the drop down list then I want to return all employees where last name = dbo.employee.lastname and age = dbo.employee.age. If someone types in just the first name then I want to return all employees where first name = pub.employees.firstname? I have been trying to do this using the SQLDatasource but cannot seem to figure it out.

View 3 Replies View Related

Ms Sql Select Command

Jan 11, 2008

I currently have a webpage that allows visitors to post links to their own website.  As a spam filter I want to create a scheduled task that selects repeat entries in the database under the column name domain.  I already made a filter to take everything out of the link the provide and leave it with just the domain name.  I tested it and it works.  Now I need a SQL command to select all the rows with repeats of the domain.  Look at the following table example to better understand what I mean uid            x            y           domain1             100        110          www.spam.com2             100         120        www.spam.com3             110         130         www.homepage.com4             210         220        www.myaspspam.com5             510          560       www.myaspspam.com  in this example I would like 1 and 2 to be selected as well as 4 and 5 into a dataadapter so that I can delete them accordingly. 

View 2 Replies View Related

Need Help With This Select Command

Jan 28, 2008

 im trying to write a select command that gets info from 1 table and counts 11 differnt things in it im not sure if this is even posiable but if it is could someone help  this is what i got for counting all of them SELECT owner, COUNT(*) AS TotalPots
FROM Items
WHERE (Name = 'Holy Potion') OR
(Name = N'Arcane Potion') OR
(Name = N'Shadow Potion') OR
(Name = N'Fire Potion') OR
(Name = N'Kinetic Potion') OR
(Name = N'Potion of Holy Resistance') OR
(Name = N'Potion of Arcane Resistance') OR
(Name = N'Potion of Shodow Resistance') OR
(Name = N'Potion of Fire Resistance') OR
(Name = N'Potion of Kinetic Resistance')
GROUP BY owner
ORDER BY COUNT(*) DESC  the 11 coloums i want are Holy, Arcane, Shadow, Fire, Kinetic, Holy Resist, Arcane Resist, Shadow resist, Fire Resist, Kinetic Resist, And Total Pots Also would like it on my Asp.net page at the bottom of the grid view to have a total row that counts all the colums up 

View 8 Replies View Related

Sql Select Command

Aug 18, 2006

Hello,everyone,i have a problem:(about BOM caculation)

The BOM is B--87700

has one outside service,and two children parts:z--877,and s--877

i have a table,this table which contains columns like this:

part_id description price(unit price) quatity

B--877 FD 82.36$(service price) 1

Z--877 Roughcast 2.36$ 4

S--877 the same 8.36$ 12

and i want to get a result of this:

part_id description price

B--877 FD (82.36+2.36*4+8.36*12)=192.12(just the result 192.12 is okay)

how can i achieve this target?

View 3 Replies View Related

OLE DB Command And Select

Sep 21, 2007

I am trying to run a select command on an OLE DB Command transform such as:

Select * from table where id = ?

I have the mapping to the parameter working and the command is working but how to map the select output to columns when you can't create output columns on the OLE DB Command?

Is this the correct transform to use?

Thanks

View 3 Replies View Related

OLE DB Command And Select

Dec 20, 2007

Thanks for this help. My problem is a little different. I have a stored procedure with an output parameter that I want to use in an OLE DB transform. I can see how to add output columns but can't figure out how to set them from the stored procedure return. Any ideas?

View 1 Replies View Related

ASP: SqlDataSource - Select Command

Aug 10, 2007

I am using  <asp:SqlDataSource ID and for the Select Command, the following, where the WHERE clause ... for an exact match (=) works correctly:
SelectCommand="SELECT [PatientID], [MedRecord] , [Accession], [FirstName], [LastName], [Address1] FROM [ClinicalPatient] WHERE (LastName = @LastName) ORDER BY [LastName]DESC">
 I would like to do a "LIKE" search where the LastName Parameter is matched using "LIKE".  In  this situation how would the syntax be written.... I tried:
LastName LIKE '%" & LastName & "%'"
But I get an error???? Any suggestions, please...
Thanks !!

View 4 Replies View Related

SqlDataSource Select Command

Nov 15, 2007

I have a SqlDataSource object that is bound to a GridView control. I have configured the SqlDataSource with a default select command. Under certain values of query strings on the URL for this page (Default.aspx), I want to change the select command. So I put the statements in the Page_Load method for Default.aspx to define SqlDataSource1.SelectCommand. The changed SelectCommand works fine for the first page of GridView data and shows 5 GridView pages, but if I switch to one of the other pages, it seems to revert to the default SelectCommand (which generates 19 GridView pages). I assume I should put my code to change the SelectCommand somewhere else. Can someone help me with where to put it? Thanks!

View 1 Replies View Related

How To Use A CheckBoxList With The Select Command

Feb 24, 2008

Hi,
I'm trying to use a CheckBoxList to display certain records in a Grid View. I have a Grid View, a CheckBoxList with four items and a SqlDataSource and when the user check or uncheck one or more items in the CheckBoxList the Grid View should show records accordingly. I’ve tried to make it work but it’s only the first checked item in the Grid View that has any effect. I use VB. Thanks 
 

View 7 Replies View Related

SessionParameters And SQL Select Command Help

Mar 24, 2008

Hi Guys,
I'm fairly new to .Net and have reached a point in the coding I can't seem to get past.
I've created a table with Visual Studio 2005 and MySQL Server 2008 (Beta) and am trying to make the "Select" button bind a result from that table (in this case, image_id) then open up that image ID in a Image details page, I've created the table in Visual Studio 2005.
Here's what I've got so far;
Page 1Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)Dim row As GridViewRow = GridView1.SelectedRowSession("session_current") = row.Cells(1).TextServer.Transfer("page2.aspx")End SubI think this page isn't at fault as it reads the parameter into a text box on page2
Page2</asp:GridView><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString3 %>"ProviderName="<%$ ConnectionStrings:ConnectionString3.ProviderName %>" SelectCommand="SELECT * FROM [profiles] WHERE ([profile_id] LIKE '%' + ? + '%')"><SelectParameters><asp:SessionParameter Name="profile_id" Type="String"/></SelectParameters>
 I'd sincerly appreciate any help, any one may be able to offer,
Cheers,
Craig

View 1 Replies View Related

How Can A Variable Used In SQL Select Command

Nov 8, 2004

select * from TABLE where user='jacky' ,it can working,but if like this:
dim name as string="jacky"
select * from TABLE where user=name
it won't doing,Can a variable used in SQL select command,if can,how to make it working.

View 2 Replies View Related

Sql Select Command Problem

Apr 21, 2005

i have to field in sql table
for example :
field1 : Father
Field2 : David,Sarah , Niki,John .
when i want to find for example sarah i can not becase near sarah is "," how can i solve this problem ?
i use this command :
"select * from table  where field2 like '" & textbox2.text & '""
but show me another records like sarah kimm or sarah dave but i want exact Sarah

View 6 Replies View Related

Defining A Select Command

May 17, 2006

I'm trying to populate a DropDownList from my SQL database. I'm using C# 2005 and when I compile my code I get an error. Compiler Error Message: CS0103: The name 'myConnection' does not exist in the current context
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default3 : System.Web.UI.Page
{
private string connectionString = WebConfigurationManager.ConnectionStrings["mewconsultingConnectionString"].ConnectionString;

protected void Page_Load(object sender, EventArgs e)
{
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection;
myCommand.CommandText = "SELECT * FROM tblPau";
myConnection.Open();
SqlDataReader myReader;
myReader = myCommand.ExecuteReader();
myReader.Read(); // The first row in the result set is now available.
lstPau.Items.Add(myReader["PauSiteName"]);
myReader.Close();
myConnection.Close();
}
}

View 1 Replies View Related

Insert-Select Command

May 21, 2001

I need to move various records from a production database to an archive database. The fields in the two databases are identical but the archive database has an additional "Transfer Date" field. Can anyone recommend an easy way to create an SQL statement to move the record from production to archive? I've tried

INSERT INTO ARCHIVE (SELECT * FROM PRODUCTION WHERE ACCOUNTNO='XYZ')

but I get an error saying the columns among the two tables do not match (obviously because of the "Transfer Date" column). Is there a way to use a similar SQL statement that will populate the "Transfer Date" column w/ today's date?

Thanks in advance for your help.

View 2 Replies View Related

Insert Command With Select Max

Oct 17, 2013

I have a table with a column called SortOrder. It's an integer. The table also has a name and a city.I want to do an Insert and fill in SortOrder with the next higher integer, of all rows with city='NY'

Insert (name,city,SortOrder) values ('Dave','NY',
select max(SortOrder)+1 from myTable where city='NY')

View 3 Replies View Related

Using Select In Push Command

May 31, 2006

Hi All,

Does anyone know if you can add columns to a local pulled table and if so can you use a select command to push the table back and exclude the added columns.

Basically I need to know if a record has been added on the PDA so I can get an ID from the server before pushing it back. I cannot alter the sql server database because it is part another application.

Cheers,

Jiggy!

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved