Dim sql = "Select subjectCode From ProgramDetails.subjects where subjectname like @subname" Using con = New SqlConnection("Data Source=EBENEZERAKAGLO\SQLEXPRESS;Initial Catalog=Naass;Integrated Security=True") Using cmd = New SqlCommand(sql, con) cmd.Parameters.AddWithValue("@subname", String.Format("%{0}%", "")) con.Open() Using rd = cmd.ExecuteReader() While rd.Read() Dim subjectCode = rd.GetInt32(0) subcode = subjectCode ' ... ' MsgBox(subjectCode) End While End Using End Using End Using
subname = Module1.sname
String.Format("%{0}%", "")
%%
cmd.Parameters.AddWithValue("@subname", subname)
Dim Sql = "Select subjectCode From ProgramDetails.subjects where subjectname=@subname;"
select * from city where city like '%apple valley%'
cmd.Parameters.AddWithValue("@subname", String.Format("%{0}%", subname))
Replace
Social Studies
cmd.Parameters.AddWithValue("@subname", "%Social Studies%")
subname
{ string sql = "select city from city where city Like @city;"; SqlConnection con = new SqlConnection("Database=StudioDatabase;Server=ILLIAC\\SQLEXPRESS;Connect Timeout=10;Integrated Security=True;Net=dbmssocn;Application Name=Calendar;"); SqlCommand cmd = new SqlCommand(sql, con); cmd.Parameters.AddWithValue("@city", "%" + "Apple Valley" + "%"); con.Open(); SqlDataReader rd = default(SqlDataReader); rd = cmd.ExecuteReader; while (rd.Read) { string cityname = rd("City").ToString; Interaction.MsgBox(cityname); } rd.Close(); rd.Dispose(); cmd = null; con.Close(); con.Dispose();}
cmd.AddParameters.AddWithValue("@subname","%Social Studies%")
Dim sql = "Select subjectCode From ProgramDetails.subjects where subjectname = @subname"... cmd.Parameters.AddWithValue("@subname", subname)...
English I
Select * from ProgramDetails.subjects where subjectname='English I';GoSelect * from ProgramDetails.subjects where subjectname='English II';Go
\SQLExpress
"Database=MyDatabaseName;Server=MyServerName;Connect Timeout=10;Integrated Security=True;Net=dbmssocn;Application Name=MyApplicationName;"
Solution 2
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)