에 안녕과 C# 1 로그인 어레이 오차의 범위 밖에 있었다 내가 서버 문자열 연결 및 로그인 버튼을 누를 때 실행 로그인있다. 사용자와 암호가 데이터베이스에 저장되어 있지 않지만 데이터베이스에있는 경우 "배열 경계에 있지 않습니다"오류가 발생하면 잘못된 오류를 반환합니다. 어떻게 내가 이걸 고칠 수 있을까 ?? 덕분에 내 연결 문자열이 내 appconfig가 파일에 있습니다 인덱스 SQL
, 문제가 될 수 있을까? 는 PROGRAM.CS 파일 #######private void btnOK_Click(object sender, EventArgs e)
{
SqlConnection con = Program.GetConnection;
SqlDataReader dr = null;
try
{
SqlCommand cmd = new SqlCommand("SELECT * FROM Users WHERE UserName='" +
txtName.Text + "'AND Password='" + textpassword.Text + "'", con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
Program.UserLoginName = dr.GetString(3);
this.Close();
}
else
MessageBox.Show("Invalid Username & Password!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
는
Using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace FrontEndV1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login());
}
public static SqlConnection GetConnection
{
get
{
string ConnectionString = ConfigurationManager.ConnectionStrings["FrontEndV1Connection"].ConnectionString;
SqlConnection con = new SqlConnection(ConnectionString);
con.Open();
return con;
}
}
public static string UserLoginName { get; set; }
}
}
-1 응답하지 않습니다. ** Users ** 테이블에 몇 개의 열이 있습니까? – adatapost
@AVD : 나는 이것이 그런 상황에서 사용자를 downvote하는 것이 옳지 않다고 생각한다. 그것은 SO stat에 따라 "18 분 전"으로 보였다. 나는 질문을 올렸을 때와 같은 상황에있을 수 있다고 생각한다. 이것은 downvote의 이유가되지 않습니다 – sll