[QUOTE=rohand;1326558]Try to execute below modified query :

[CODE]
string C_ID = Request.QueryString["C_ID"]; (this works)

SELECT mcl.MC_ID as MC_ID, m.M_title as Modules
From Modules m
Join Module_course_link mcl on mcl.M_ID = m.M_ID
Where
mcl.C_ID = C_ID

[/CODE]

Thank you, but I received an error:
[COLOR="red"]Syntax error in FROM clause.[/COLOR]

Hi everyone,

I am trying to populate a gridview.

this is my table structure:
Modules - M_ID, M_title (this is where the module info is stored)
Module_course_link - MC_ID, M_ID, C_ID (this table links the Modules and Courses table)
Courses - C_ID, C_title (this is where the course info is stored)

this is where I get the C_ID
<code>string C_ID = Request.QueryString["C_ID"]; (this works)</code>

what I need help with is, to populate the gridview, at the moment I'm using this syntax,
I want the MC_ID to be the DataKeyName of the gridview, at the moment only M_title AS Modules are displayed.

How can I change the select query to do this and not return the error:
At most one record can be returned by this subquery.

[code]
AccessDataSource1.SelectCommand =
"SELECT M_title AS Modules FROM Modules WHERE M_ID IN (Select MC_ID From Module_course_link Where C_ID= " + C_ID + ")";
[/code]

Hi,
I've got a door_order table which I export to excel, now I have to make it so that underneath each door_order the products are listed from door_product table, please not that this can be more than one product for that order.

This is my code so far

public DataTable GetData(SqlCommand cmd)
    {
        DataTable dt = new DataTable();
        SqlConnection con =
                    new SqlConnection(@"Data Source=;Initial Catalog=bargaindoors;Persist Security Info=True;User ID=;Password=");
        SqlDataAdapter sda = new SqlDataAdapter();
        cmd.CommandType = CommandType.Text;
        cmd.Connection = con;
        try
        {
            con.Open();
            sda.SelectCommand = cmd;
            sda.Fill(dt);
            return dt;
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            con.Close();
            sda.Dispose();
            con.Dispose();
        }
    }

    protected void Calculate_Click(object sender, EventArgs e)
    {
        string startDate = testinput.Text;
        string endDate = testinput2.Text;

        string strQuery = "SELECT O_ID AS ID, O_Datecreated AS 'Date Created', O_Ath AS Ath, Amount, Delivery, CU_Title AS Title, CU_F_Name AS Name, CU_L_Name AS Surname, CU_Address1 AS Address1, CU_Address2 AS Address2, CU_City AS City, CU_County AS County, CU_Country AS Country, CU_Postal AS Postal, PO,  '\"' + Instructions + '\"', O_ID AS products FROM door_order WHERE O_Ath='A' AND " +
             "O_Datecreated BETWEEN '" + startDate + "' AND '" + endDate + "'";
        SqlCommand cmd = new SqlCommand(strQuery);
        //Response.Write(startDate);
        DataTable dt = GetData(cmd);

        string attachment = "attachment; filename=Enquiry.xls";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/vnd.ms-excel";
        string tab = "";
        foreach (DataColumn dc in dt.Columns)
        {
            Response.Write(tab + dc.ColumnName);
            tab = "\t";
        }
        Response.Write("\n");
        int i;
        foreach (DataRow dr in dt.Rows)
        {
            tab = "";
            for (i = 0; i < dt.Columns.Count; i++)
            {
                Response.Write(tab ...

How can I use html tags in print preview?

hallo,
I want to create a print preview for an invoice. What I'm having problems with is, most of the content in the print preview is pulled from a database and not the form, I am not sure how to implement this into the code, plus how would I change the font size, color, position...

[CODE]
private void preview_btn_Click(object sender, EventArgs e)
{
ThePrintDocument.PrintPage +=
new System.Drawing.Printing.PrintPageEventHandler(PrintPage);
string strText = "test" // HOW CAN I ADD FROM DB
myStringReader = new System.IO.StringReader(strText);
PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();
printPreviewDialog1.Width = 1100;
printPreviewDialog1.Height = 900;
printPreviewDialog1.Document = this.ThePrintDocument;
printPreviewDialog1.ShowDialog();
}
[/CODE]

I'm creating a Content Management System. Users must be able to delete content from a database. This does not delete or give an error message, it just does nothing.

[code]
protected void deleteBut_Click(object sender, EventArgs e)
{
string A_ID = Request.QueryString["A_ID"];

    string sel = "DELETE FROM acomodation WHERE A_ID=" + A_ID;
    string s = "Provider=Microsoft.Jet.OLEDB.4.0; " +
     "Data Source=" + Server.MapPath("calendar.mdb");

    OleDbConnection con = new OleDbConnection(s);
    con.Open();
    OleDbCommand cmd = new OleDbCommand(sel, con);
    cmd.ExecuteNonQuery();
    con.Close();
    con.Dispose();
}

[/code]

Cool thanks alot!

[code]
SqlConnection cnn = new SqlConnection(connectionString);

        SqlCommand comm = new SqlCommand();
        comm.CommandType = CommandType.Text;
        comm.Connection = cnn;

        comm.CommandText = "INSERT INTO invoice (c_id=@c_id, date_added=@date_added, customer=@customer, status=@status, items=@items, description=@description, quantity=@quantity, unit_value=@unit_value, total=@total, notes=@notes, notes_internal=@notes_internal, ref=@ref, payment_ref=@payment_ref)";

        comm.Parameters.AddWithValue("@c_id", Int32.Parse(customer_dd.SelectedValue.ToString()));
        comm.Parameters.AddWithValue("@date_added", DateTime.Today.ToShortDateString());
        comm.Parameters.AddWithValue("@customer", customer_dd.Text);
        comm.Parameters.AddWithValue("@status", Int32.Parse(status));
        comm.Parameters.AddWithValue("@items", "Item");
        comm.Parameters.AddWithValue("@description", "Descrioption");
        comm.Parameters.AddWithValue("@quantity", "Qty");
        comm.Parameters.AddWithValue("@unit_value", "Unit_Value");
        comm.Parameters.AddWithValue("@total", "Line_Total");
        comm.Parameters.AddWithValue("@notes", notes_txt.Text);
        comm.Parameters.AddWithValue("@notes_internal", internal_txt.Text);
        comm.Parameters.AddWithValue("@ref", reference);
        comm.Parameters.AddWithValue("@payment_ref", null);

        cnn.Open();
        comm.ExecuteNonQuery();
        cnn.Close();

[/code]

now I receive the error:
Incorrect syntax near '='.

Thanks for all the replys.

rohand
I tried what you suggested but still get the error.
pInsert[0] = new SqlParameter("@i1", SqlDbType.VarChar, 5, customer_dd.SelectedValue.ToString());
pInsert[0] = new SqlParameter("@i1", SqlDbType.Int, 5, Int32.Parse(customer_dd.SelectedValue.ToString());

dnanetwork
In your code you are updating the record, I want to add a new record. Will this work for adding?

I'm trying to insert a record from a DataGridView into a database, but I receive this error:
[COLOR="red"]Parameterized Query '(@i1 int,@i2 varchar(50),@i3 varchar(50),@i4 varchar(50),@i5 var' expects parameter @i1, which was not supplied.[/COLOR]

I have tested with a BreakPoint that c_id is not null, it does have a value.

*Note c_id is only a link to another table, it is not the invoice tables id.

[CODE]
string reference = "INV" + Random();

        string status = "0";

        SqlConnection cnn = new SqlConnection(connectionString);

        string sqlInsert =
            "INSERT INTO invoice(c_id, date_added, customer, status, items, description, quantity, unit_value, total, notes, notes_internal, ref, payment_ref) values(@i1,@i2,@i3,@i4,@i5,@i6,@i7,@i8,@i9,@i10,@i11,@i12,@i13)";

        SqlParameter[] pInsert = new SqlParameter[13];

        pInsert[0] = new SqlParameter("@i1", SqlDbType.Int, 5, customer_dd.SelectedValue.ToString());
        pInsert[1] = new SqlParameter("@i2", SqlDbType.VarChar, 50, DateTime.Today.ToShortDateString());
        pInsert[2] = new SqlParameter("@i3", SqlDbType.VarChar, 50, customer_dd.Text);
        pInsert[3] = new SqlParameter("@i4", SqlDbType.VarChar, 50, status);
        pInsert[4] = new SqlParameter("@i5", SqlDbType.VarChar, 50, "Item");
        pInsert[5] = new SqlParameter("@i6", SqlDbType.VarChar, 50, "Descrioption");
        pInsert[6] = new SqlParameter("@i7", SqlDbType.VarChar, 50, "Qty");
        pInsert[7] = new SqlParameter("@i8", SqlDbType.VarChar, 50, "Unit_Value");
        pInsert[8] = new SqlParameter("@i9", SqlDbType.VarChar, 50, "Line_Total");
        pInsert[9] = new SqlParameter("@i10", SqlDbType.VarChar, 50, notes_txt.Text);
        pInsert[10] = new SqlParameter("@i11", SqlDbType.VarChar, 50, internal_txt.Text);
        pInsert[11] = new SqlParameter("@i12", SqlDbType.VarChar, 50, reference);
        pInsert[12] = new SqlParameter("@i13", SqlDbType.VarChar, 50, null);

        SqlCommand cmdInsert = new SqlCommand(sqlInsert,cnn);

        cmdInsert.Parameters.AddRange(pInsert);
        SqlDataAdapter da = new SqlDataAdapter();
        da.InsertCommand  = cmdInsert;
        da.Update(ds, "invoice");
        ds.AcceptChanges();

[/CODE]

Thanks man, it solved it.

I've got a DropDown which I populate from a database. When an item is selected I want to redirect to another page with the selected id, but the problem is it passes "1" no matter what was selected.

[code]
protected void Page_Load(object sender, EventArgs e)
{
Populate();
}

public void Populate()
{
    OleDbConnection con = new OleDbConnection(
       "Provider=Microsoft.Jet.OLEDB.4.0; " +
       "Data Source=" + Server.MapPath("connect.mdb"));

    con.Open();

    string strQuery = "SELECT A_ID, Title_eng FROM C_about";
    OleDbCommand cmd = new OleDbCommand(strQuery, con);
    OleDbDataReader reader = cmd.ExecuteReader();

    titleSelection.DataSource = reader;
    titleSelection.DataValueField = "A_ID";
    titleSelection.DataTextField = "Title_eng";
    titleSelection.DataBind();

    con.Close();
    con.Dispose();
}

protected void titleSelection_SelectedIndexChanged(object sender, EventArgs e)
{
    string A_ID = titleSelection.SelectedValue.ToString();

    Response.Redirect("aboutEdit.aspx?A_ID=" + A_ID);
}

[/code]

this is the view source:
Title:<br />
<select name="titleSelection" onchange="javascript:setTimeout('__doPostBack(\'titleSelection\',\'\')', 0)" id="titleSelection">
<option selected="selected" value="1">WHO WE ARE</option>
<option value="2">WHAT WE DO</option>

<option value="3">Permanent Placements</option>
<option value="4">Temporary staff</option>
<option value="5">Training &amp; Development</option>
<option value="6">CV Writing Tips</option>
<option value="7">Jobs Titles &amp; Descriptions</option>

<option value="8">Looking for Talent?</option>
<option value="9">Looking for a Job</option>
<option value="10">Register</option>

Ok, I basically put a form tag in the master page for all the content, if you look at my master page I've only got a form tag for the login, Which does not apply to the ContentPlaceHolder.

I restructed all the pages. All works now

Can you have a look at the master page, maybe I'm missing something. I've tried different machines and same thing.

[code]
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="train.master.cs" Inherits="train" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Train Station</title>
<link href="style.css" rel="stylesheet" type="text/css" />

<link rel="stylesheet" href="js-style.css" type="text/css" media="screen" />
<link rel="stylesheet" href="fx.slide.css" type="text/css" media="screen" />
<script type="text/javascript" src="js/mootools-1.2-core-yc.js"></script>
<script type="text/javascript" src="js/mootools-1.2-more.js"></script>
<script type="text/javascript" src="js/fx.slide.js"></script>    

</head>

<body>
<div id="login">
<div class="loginContent">
<form action="#" method="post" runat="server">
<label for="log"><b>Username: </b></label>
<input class="field" type="text" name="log" runat="server" id="log" value="" size="23" />
<label for="pwd"><b>Password:</b></label>
<input class="field" type="password" name="pwd" runat="server" id="pwd" size="23" />
<input type="submit" name="submit" value="" class="button_login" onclick="submitButton_Click"/>
<input type="text" name="redirect_to" value="" runat="server" />
</form>
<div class="left">
<label for="rememberme"><input name="rememberme" id="rememberme" class="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</label></div>
<div class="right">Not a member? <a href="Register.aspx">Register</a> | <a href="#">Lost your password?</a></div>
</div>
<div class="loginClose"><a href="#" id="closeLogin">Close Panel</a></div>
</div> <!-- /login -->

<div id="containerl">
    <div id="top">
    <!-- login -->
        <ul class="login">
            <li class="left">&nbsp;</li>
            <li>Hello&nbsp; <asp:Label ID="status" runat="server" Text=" Guest" /></li>
            <li>|</li>
            <li><a id="toggleLogin" href="#">Log In</a></li>
        </ul> <!-- / login -->
    </div> <!-- / top -->
</div><!-- / container -->

<div class="clearfix"></div>

<div id="container">
    <object width="593" height="47" style="padding:0 0 10px 350px">
                <param name="movie" value="menu.swf" />
                <embed src="images/menu.swf" width="593" height="47" />
    </object>

<!-- header -->
<div id="header">
     <div id="logo"><a href="#">Train Station</a></div>
        <div id="submenu"> 
            <%-- create --%>
      </div>
</div>      
<!--end header -->

<!-- content -->
    <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
        <div id="text">
        </div>
    </asp:contentplaceholder>
  </div>
 <!-- end content -->

<!-- footer -->
<div id="footer">
<div ...

Can someone please help me with why this button is not working, I've tried putting it in <for id="" runat="server">, but then I get the error: A page can have only one server-side Form tag.

When the button is clicked nothing happens.

[code]
<%@ Page Language="C#" MasterPageFile="~/train.master" AutoEventWireup="true" validateRequest="false"
CodeFile="TrainStationTutorial.aspx.cs" Inherits="TrainStationTutorial" Title="Admin | Tutorial" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<link href="style2.css" rel="stylesheet" type="text/css" />

<div id="main">
<center>
<object width="740" height="207" >
<param name="movie" value="admin_menu.swf" />
<embed src="images/admin_menu.swf" width="960" height="170" />
</object>

    <h2>Admin | Tutorial</h2>
    <br />
    <div class="about">
        <div class="contactform">
            <div id="li1">
                <asp:Label ID="titleLabel" runat="server" Text="Title" CssClass="label" />
                <asp:TextBox ID="titleText" runat="server" CssClass="inputtext" />
            </div>
            <div id="li2">
                <asp:Label ID="categoryLabel" runat="server" Text="Category" CssClass="label" />            
                <asp:ImageButton ID="addCategory"  runat="server" ImageUrl="images/add.jpg" /> 
            </div>
            <div id="li3">
                <asp:Label ID="tutorialLabel" runat="server" Text="Tutorial" CssClass="label" />
                <asp:TextBox ID="tutorialArea" runat="server" CssClass="textarea" TextMode="MultiLine" />
            </div>
            <div id="li4">
                <asp:ImageButton ID="submitButton"  runat="server" ImageUrl="images/submit.jpg" OnClick="ImageButton1_Click" /> 
                <asp:Label ID="messageLabel" runat="server" Font-Size="10px" ForeColor="Red" />
            </div>
        </div>
    </div>
    </center>

</asp:Content>
[/code]

[code]
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
messageLabel.Text = "Working";
}
[/code]

Thanks it works!

Thanks prashantchalise,
I will try this.

Hey, this is an update of my code:

[code]
<body>
<div id="text">
<div class="body_resize">
<div class="about" >
<h2>Registration</h2>
<form method="post" id="contactform">
<ol>
<li>
<label for="firstName" >Name</label>
<input id="firstName" runat="server" name="nameTextBox" class="text" />
</li>
<li>
<label for="country">Country</label>
<input id="country" runat="server" name="countryTextBox" class="text" />
</li>
<li>
<label for="email">E-Mail Address</label>
<input id="email" runat="server" name="emailTextBox" class="text" />
</li>
<li>
<label for="email">Username</label>
<input id="user" runat="server" name="usernameTextBox" class="text" />
</li>
<li>
<label for="pass1">Password</label>
<input id="pass1" runat="server" name="pass1TextBox" class="text" />
</li>
<li>
<label for="pass2">Confirm Password</label>
<input id="pass2" runat="server" name="pass2TextBox" class="text" />
</li>
</ol>
</form>
</div>
</div>
<form id="form1" runat="server">
<asp:ImageButton ID="submitButton"
runat="server" src="images/send.gif" OnClick="submitButton_Click" /><br />
<asp:Label ID="message" runat="server" />
</form>
[/code]

[code]
public partial class Register : System.Web.UI.Page
{
string scon =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|db_TrainStation.mdb";

protected void Page_Load(object sender, EventArgs e)
{

}

protected void submitButton_Click(object sender, ImageClickEventArgs e)
{
    string str =
       "INSERT INTO ts_registration(r_name, r_country, r_email, r_username, r_pass1, r_pass2)values(r_name, r_country, r_email, r_username, r_pass1, r_pass2)";
    string id = "Select @@Identity";
    int r_id;
    using (OleDbConnection con = new OleDbConnection(scon))
    {
        using (OleDbCommand cmd = new OleDbCommand(str, con))
        {
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.AddWithValue("r_name", firstName.Value);
            cmd.Parameters.AddWithValue("r_country", country.Value);
            cmd.Parameters.AddWithValue("r_email", email.Value);
            cmd.Parameters.AddWithValue("r_username", user.Value);
            cmd.Parameters.AddWithValue("r_pass1", pass1.Value);
            cmd.Parameters.AddWithValue("r_pass2", pass2.Value);
            con.Open();
            cmd.ExecuteNonQuery();
            cmd.CommandText = id;
            r_id = (int)cmd.ExecuteScalar();
        }
    } 
}

}
[/code]

When the submit button is pressed, a new record in the database is created but there are no values from the input fields, they are all empty.

I got this code off a site, with a really nice layout and style, I've never worked with input field, so I'm stuck how can I save this to a database.
I tried changing everything to a <asp:Label> and <asp:TextBox> but then I do not get the same layout.

[code]
<body>
<div id="text">
<div class="body_resize">
<div class="about">
<h2>Registration</h2>
<form method="post" id="contactform">
<ol>
<li>
<label for="firstName">Name</label>
<input id="firstName" name="nameTextBox" class="text" />
</li>
<li>
<label for="country">Country</label>
<input id="country" name="countryTextBox" class="text" />
</li>
<li>
<label for="email">E-Mail Address</label>
<input id="email" name="emailTextBox" class="text" />
</li>
<li>
<label for="email">Username</label>
<input id="user" name="usernameTextBox" class="text" />
</li>
<li>
<label for="pass1">Password</label>
<input id="pass1" name="pass1TextBox" class="text" />
</li>
<li>
<label for="pass2">Confirm Password</label>
<input id="pass2" name="pass2TextBox" class="text" />
</li>
<li class="buttons">
<input type="image" name="imageField" id="imageField" src="images/send.gif" onclick="Submit" />
</li>
</ol>
</form>
</div>
</div>
</div>
<label for="test"></label>
</body>
[/code]

I tried this to test:
[code]
public partial class Register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Submit()
{
    test.Text = "Working";
}

}
[/code]

but I receive an error: The name 'test' does not exist in the current context

commented: Read forum rules. Thread belongs to ASP.NET -2

No that won't work, what I'm trying to do is called circular reference where values depend on each other in a calculation.

with these answers:
a = 27
b = 41

the calculation should then be
a = 41 + 12
b = 27 + 14

my answers are:
a = 27
b = 41

you assigned 15 to b and 12 to c = 27
I need the e.g(41) for b

you see, a should use b's final answer and b should use a's final answer.

two values are used to calculate each other
e.g a = b + c
b = a + d
this is called a circular reference.

Can someone please help me to create a circular reference
I need to add a to b and b to a. I've been looking everywhere can this be accomplished with enum or structs?

Please help me

Hi I'm coding in c# and I'm usiing the IIR function of Microsoft.VisualBasic.

I need values for 6 years that's 72months

[code]
if (i <= 72)
{
values[i] += C158_Calc;
}

    B162_Calc = Financial.IRR(ref values, 0.1) * 12;
    row9["Month1"] = String.Format("{0:#,###,###,###.##}", B162_Calc);

[/code]

this gives me this error:

Arguments are not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Arguments are not valid.

but if I say up to 10months it works, more than that not.

Any help please.

I just removed
[code]
shippingSelection.SelectedIndex = 0;
[/code]

now it works, I think it was changing the DropDown to 0 the entire time.

Ok I will have a check with the server thanks.

[code]<%@ Page Language="C#" MasterPageFile="~/Admin.master" AutoEventWireup="true"
CodeFile="AdminCategories.aspx.cs" Inherits="AdminCategories" ValidateRequest="false" Title="Admin : Categories" %>[/code]

Is this correct? Cause it only works on the localhost, not on the server.