pita
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Tolong... Nak tahu cara2 connection db using VS. (ASP.net using C#)

4 posters

Go down

Tolong... Nak tahu cara2 connection db using VS. (ASP.net using C#) Empty Tolong... Nak tahu cara2 connection db using VS. (ASP.net using C#)

Post by nurukeen Tue Jan 05, 2010 12:59 pm

Kengkawan tolonglah settle kan masalah saya ni.. Saya nk buat connection ke database tapi saya xtahu caranya.. Saya ada dapatkan satu coding C# tapi saya tak tahu macam mana nak wat connection tu.. Saya buat Sistem berkenaan PITA System: Module E-thesis. Coding tu seperti dibawah:


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.Web.Security;
using System.Data.SqlClient;
using System.Configuration;

namespace NorthCSharp
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtUserName;
protected System.Web.UI.WebControls.RequiredFieldValidator rvUserValidator;
protected System.Web.UI.WebControls.TextBox txtPassword;
protected System.Web.UI.WebControls.RequiredFieldValidator rvPasswordValidator;
protected System.Web.UI.WebControls.Button cmdSubmit;
protected System.Web.UI.WebControls.ValidationSummary Validationsummary1;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.Label lblMessage2;

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);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.cmdSubmit.Click += new System.EventHandler(this.cmdSubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void cmd_Click(object sender, System.EventArgs e)
{
if (Page.IsValid)
{
if (DBConnection(txtUser.Text.Trim(), txtPassword.Text.Trim()))
{
FormsAuthentication.RedirectFromLoginPage(txtUser.Text, false);
}
else
{
lblMessage.Text = "Invalid Login, please try again!";
}
}

}
private bool DBConnection(string txtUser, string txtPassword)
{
SqlConnection myConn = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCmd = new SqlCommand("sp_ValidateUser", myConn);
myCmd.CommandType = CommandType.StoredProcedure;

SqlParameter objParam1;
SqlParameter objParam2;
SqlParameter returnParam;

objParam1 = myCmd.Parameters.Add("@UserName", SqlDbType.VarChar);
objParam2 = myCmd.Parameters.Add("@Password", SqlDbType.VarChar);
returnParam = myCmd.Parameters.Add("@Num_of_User", SqlDbType.Int);

objParam1.Direction = ParameterDirection.Input;
objParam2.Direction = ParameterDirection.Input;
returnParam.Direction = ParameterDirection.ReturnValue;

objParam1.Value = txtUser;
objParam2.Value = txtPassword;

try
{
if (myConn.State.Equals(ConnectionState.Closed))
{
myConn.Open();
myCmd.ExecuteNonQuery();
}
if ((int)returnParam.Value < 1)
{
lblMessage.Text = "Invalid Login!";
return false;
}
else
{
myConn.Close();
return true;
}
}
catch (Exception ex)
{
lblMessage2.Text = ex + "Error Connecting to the database";
return false;
}

}

}
}

Tolong ye.. apa yang x kena coding ni..

nurukeen
Stalker
Stalker

Posts : 1
Join date : 2010-01-05

Back to top Go down

Tolong... Nak tahu cara2 connection db using VS. (ASP.net using C#) Empty Re: Tolong... Nak tahu cara2 connection db using VS. (ASP.net using C#)

Post by TMUkmkd Tue Jan 05, 2010 1:18 pm

dah try cara ni: VBMySQL.com
TMUkmkd
TMUkmkd
Moderator
Moderator

Posts : 21
Join date : 2010-01-05
Age : 36
Location : Uplink Agent Server

http://adamasalahbarunakcari.blogspot.com/

Back to top Go down

Tolong... Nak tahu cara2 connection db using VS. (ASP.net using C#) Empty Re: Tolong... Nak tahu cara2 connection db using VS. (ASP.net using C#)

Post by nkunda Tue Jan 05, 2010 3:50 pm

1) Soalan tak lengkap, tunjukkan semua contents dari fail lain seperti web.config
2) Kena create 1 Stored procedure bernama 'sp_ValidateUser' dalam database
nkunda
nkunda
Moderator
Moderator

Posts : 4
Join date : 2010-01-05

Back to top Go down

Tolong... Nak tahu cara2 connection db using VS. (ASP.net using C#) Empty Re: Tolong... Nak tahu cara2 connection db using VS. (ASP.net using C#)

Post by Mr Sherlock Holmes Sat Jan 09, 2010 11:51 pm

connection database MySQL dgn matlab??

Mr Sherlock Holmes
Script-Kiddies
Script-Kiddies

Posts : 10
Join date : 2010-01-09

Back to top Go down

Tolong... Nak tahu cara2 connection db using VS. (ASP.net using C#) Empty Re: Tolong... Nak tahu cara2 connection db using VS. (ASP.net using C#)

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum