Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
S

Stoffy1972

@Stoffy1972
About
Posts
9
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Generate Sequential Number without database
    S Stoffy1972

    Sorry. Sequential - i did not recognize it. It's late at night :zzz:

    ASP.NET help question csharp asp-net database

  • Generate Sequential Number without database
    S Stoffy1972

    If you can use a string, try System.Guid.NewGuid().ToString(). It's always unique. Read this[(MSDN)]

    ASP.NET help question csharp asp-net database

  • displaying problem
    S Stoffy1972

    Maybe 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
    
    ASP.NET csharp database help asp-net sql-server

  • SQL INSERT ISSUE
    S Stoffy1972

    The 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
    
    Database help sharepoint database sales

  • java script code error
    S Stoffy1972

    It's just invalid javascript. use double quotes!

    ...

    XML / XSL java javascript tools help

  • Secure storage
    S Stoffy1972

    Something that may help you is the Namespace System.IO.IsolatedStorage, for example IsolatedStorageFile-Class. Sorry, no time to do some tests but read this[^] to get an idea.

    C# csharp c++ json help

  • refresh context
    S Stoffy1972

    Have 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.

    LINQ csharp linq help

  • Install SQL Server 2008 R2 Express in one installation file
    S Stoffy1972

    Indeed, 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.

    C# csharp database question sql-server dotnet

  • SQL INSERT ISSUE
    S Stoffy1972

    Hello 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

    Database help sharepoint database sales
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups