Sorry. Sequential - i did not recognize it. It's late at night :zzz:
Stoffy1972
Posts
-
Generate Sequential Number without database -
Generate Sequential Number without database -
displaying problemMaybe this is not the easiest solution, but it works for me...
<asp:Repeater runat="server" ID="Repeater1" DataSourceID="dsLocations"> <HeaderTemplate> Items<br /> </HeaderTemplate> <ItemTemplate> <b><%# DataBinder.Eval(Container.DataItem, "City") %></b> <b><%# DataBinder.Eval(Container.DataItem, "State") %></b> <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# DataBinder.Eval(Container.DataItem,"LocationID") %>' /> <asp:Repeater ID="Repeater2" runat="server" DataSourceID="dsUserData"> <ItemTemplate> <p> <%# DataBinder.Eval(Container.DataItem, "LastName") %>, <%# DataBinder.Eval(Container.DataItem, "FirstName") %></br> </p> </ItemTemplate> </asp:Repeater> <asp:SqlDataSource ID="dsUserData" runat="server" ConnectionString="server=.\\SQLEXPRESS;Initial Catalog=LinqTest;Integrated Security=true" SelectCommand="SELECT \* FROM UserData Where LocationID = @LocationID" OnSelecting="dsUserData\_Selecting"> <SelectParameters> <asp:Parameter Name="LocationID" Type="Int32" /> </SelectParameters> </asp:SqlDataSource> </ItemTemplate> <SeparatorTemplate> <br /> <br /> <br /> </SeparatorTemplate> </asp:Repeater> <asp:SqlDataSource ID="dsLocations" runat="server" ConnectionString="server=.\\SQLEXPRESS;Initial Catalog=LinqTest;Integrated Security=true" SelectCommand="SELECT \* FROM Location"></asp:SqlDataSource>
Code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}protected void dsUserData\_Selecting(object sender, SqlDataSourceSelectingEventArgs e) { HiddenField hf = Repeater1.Controls\[1\].F
-
SQL INSERT ISSUEThe first stored procedure:
CREATE PROCEDURE [dbo].[InsertLocation]
(
@City nvarchar(50),
@State nvarchar(50),
@LocationID int out
)
AS
INSERT INTO [Location] (City,State)
VALUES (@City, @State)SELECT @LocationID = SCOPE\_IDENTITY()
GO
and the second:
CREATE PROCEDURE [dbo].[InsertUserData]
(
@LocationID int,
@FirstName nvarchar(25),
@LastName nvarchar(25)
)
AS
SET NOCOUNT ON;INSERT INTO \[UserData\] (LocationID, FirstName, LastName) (SELECT @LocationID, @FirstName, @LastName)
GO
My code, in c#: Assuming that the array of names is filled with items
private static void insertData() { try { //Create connection string using SqlConnectionStringBuilder SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(); sb.DataSource = ".\\\\SQLEXPRESS"; sb.InitialCatalog = "Database"; sb.IntegratedSecurity = true; // Create SqlConnection using (SqlConnection cn = new SqlConnection(sb.ToString())) { // Open the connection cn.Open(); // Create command to insert location SqlCommand insertLocationCommand = new SqlCommand("InsertLocation", cn); insertLocationCommand.CommandType = CommandType.StoredProcedure; // Add first parameter for City (nvarchar) insertLocationCommand.Parameters.Add("@City", SqlDbType.NVarChar).Value = "City1"; // Add second parameter for State (nvarchar) insertLocationCommand.Parameters.Add("@State", SqlDbType.NVarChar).Value = "State1"; // Add third parameter for LocationID (int)... insertLocationCommand.Parameters.Add("@LocationID", SqlDbType.Int).Value = 0; // ... and mark it as OUTPUT-Parameter insertLocationCommand.Parameters\["@LocationID"\].Direction = ParameterDirection.Output; // Execute command... insertLocationCommand.ExecuteNonQuery(); // ... and get value of out parameter int locationID = (int)insertLocationCommand.Parameters\["@LocationID"\].Value; // Create command to insert user data SqlCommand insertUserDataCommand = new SqlCommand("Ins
-
java script code errorIt's just invalid javascript. use double quotes!
...
-
Secure storage -
refresh contextHave you tried to add the new record using the binding source. In that case the record should appear automatically in the datagrid, then accept changes in context and it should be written to database too.
-
Install SQL Server 2008 R2 Express in one installation fileIndeed, don't force your customer to install sql express. I agree to PIEBALDconsult post. Maybe its the easiest way to create your installation, but its the wrong way. Your installation should get the required data (connection settings etc.), check the connection, then it should install the database. If the connection fails, cancel the setup.
-
SQL INSERT ISSUEHello bapu2889, i agree to Matt U. if you want to get fast and good answers, don't SHOUT. To your problem. You're calling a stored procedure which has 5 parameters (in). When you use more than one pair of names, your code creates a sqlcommand with 7 parameters, 9 parameters and so on. When i try your code, i am getting an sqlexception because there are too many parameters. The exception you are getting is an conversion error in the catch-clause. Sorry, but i can't find this out because i haven't installed vb.net. Try this: Insert the location data (change your sp, return the id of the new location as out parameter). Insert each of the userdata with the id of the new location (execute second sp in a loop, set parameters). hth stoffy