Click here to Skip to main content
15,892,746 members
Home / Discussions / C#
   

C#

 
AnswerRe: C#/SQL Question Pin
Colin Angus Mackay7-Jun-06 8:11
Colin Angus Mackay7-Jun-06 8:11 
QuestionRe: C#/SQL Question Pin
leckey7-Jun-06 8:15
leckey7-Jun-06 8:15 
AnswerRe: C#/SQL Question Pin
Colin Angus Mackay7-Jun-06 8:29
Colin Angus Mackay7-Jun-06 8:29 
GeneralRe: C#/SQL Question Pin
leckey7-Jun-06 8:36
leckey7-Jun-06 8:36 
GeneralRe: C#/SQL Question Pin
leckey7-Jun-06 8:55
leckey7-Jun-06 8:55 
GeneralRe: C#/SQL Question Pin
Josh Smith7-Jun-06 9:01
Josh Smith7-Jun-06 9:01 
GeneralRe: C#/SQL Question Pin
Colin Angus Mackay7-Jun-06 9:03
Colin Angus Mackay7-Jun-06 9:03 
GeneralRe: C#/SQL Question Pin
leckey7-Jun-06 9:16
leckey7-Jun-06 9:16 
Okay...here is all the code...
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;

namespace WebBasedPartsDB
{
///
/// Summary description for WebForm1.
///

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblPartNumber;
protected System.Web.UI.WebControls.Button btnSearchPartNumber;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.TextBox txtPartNumber;
protected string strPartNumberInput;

//Get the SQL connection string from the web.config file
public String strConnectSQL = (ConfigurationSettings.AppSettings["ConnectionString"]);

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.btnSearchPartNumber.Click += new System.EventHandler(this.btnSearchPartNumber_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnSearchPartNumber_Click(object sender, System.EventArgs e)
{
strPartNumberInput = txtPartNumber.Text;
int partNumber = Convert.ToInt32(strPartNumberInput);
string SQLString = "Select * FROM Costs where Costs.PartID = @PartID";
SqlCommand cmd = new SqlCommand();
cmd.Connection = strConnectSQL;
cmd.CommandText = SQLString;
cmd.Parameters.Add ("@PartID", partNumber);
//Pass the command, not the string
BindGrid (strConnectSQL, SQLString, DataGrid1 );
//BindGrid(strConnectSQL, cmd, DataGrid1);
}
//**********************************************************
//BindData()
//**********************************************************
private void BindGrid (string DBconnectString, string sqlCommand, System.Web.UI.WebControls.DataGrid DGrid)
{
// create data connection
SqlConnection conn = new SqlConnection(DBconnectString);

// Call SP from db
SqlCommand command = new SqlCommand(sqlCommand, conn);

// create data adapter
SqlDataAdapter adapter = new SqlDataAdapter(command);

// create and fill dataset
DataSet ds = new DataSet();
adapter.Fill(ds);

// fill and bind data to Datagrid
DGrid.DataSource = ds;
DGrid.DataBind();
// Close Connection
conn.Close();
}

}
}


The only compile error I'm getting is 'Cannot implicitly convert type 'string' to 'System.Data.SqlClient.SqlConnection' where I highlighted....

Sorry, folks. I'm a project manager who has been thrown into programming. I'm sure this seems simple to you!
GeneralRe: C#/SQL Question Pin
Josh Smith7-Jun-06 9:29
Josh Smith7-Jun-06 9:29 
GeneralRe: C#/SQL Question Pin
leckey7-Jun-06 9:31
leckey7-Jun-06 9:31 
GeneralRe: C#/SQL Question [modified] Pin
Josh Smith7-Jun-06 9:38
Josh Smith7-Jun-06 9:38 
GeneralRe: C#/SQL Question--New Problem Pin
leckey7-Jun-06 9:47
leckey7-Jun-06 9:47 
GeneralRe: C#/SQL Question--New Problem Pin
Josh Smith7-Jun-06 9:51
Josh Smith7-Jun-06 9:51 
GeneralRe: C#/SQL Question--New Problem Pin
leckey7-Jun-06 9:58
leckey7-Jun-06 9:58 
GeneralRe: C#/SQL Question--New Problem Pin
Josh Smith7-Jun-06 10:12
Josh Smith7-Jun-06 10:12 
GeneralRe: C#/SQL Question--New Problem Pin
leckey7-Jun-06 10:20
leckey7-Jun-06 10:20 
GeneralRe: C#/SQL Question--New Problem Pin
Josh Smith7-Jun-06 10:38
Josh Smith7-Jun-06 10:38 
GeneralRe: C#/SQL Question--New Problem Pin
leckey7-Jun-06 10:44
leckey7-Jun-06 10:44 
GeneralRe: C#/SQL Question--New Problem Pin
Josh Smith7-Jun-06 10:54
Josh Smith7-Jun-06 10:54 
GeneralRe: C#/SQL Question Pin
Colin Angus Mackay7-Jun-06 12:23
Colin Angus Mackay7-Jun-06 12:23 
GeneralRe: C#/SQL Question Pin
leckey8-Jun-06 3:32
leckey8-Jun-06 3:32 
GeneralRe: C#/SQL Question Pin
Colin Angus Mackay8-Jun-06 8:28
Colin Angus Mackay8-Jun-06 8:28 
QuestionCalling identically named properties Pin
MartinSmith7-Jun-06 6:24
MartinSmith7-Jun-06 6:24 
AnswerRe: Calling identically named properties Pin
Dustin Metzgar7-Jun-06 6:48
Dustin Metzgar7-Jun-06 6:48 
AnswerRe: Calling identically named properties Pin
Wjousts7-Jun-06 6:52
Wjousts7-Jun-06 6:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.